Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大家看看我怎么老是WA!! 测试数据都对了的!!郁闷之极啊

Posted by wangyang788544 at 2005-09-02 17:02:32 on Problem 1309
#include<string>
#include<stdio.h>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	long a[10000];
	int i,j,flag;
	long n;
	while(cin>>n&&(n>=0))
	{
		j=flag=0;
		for(i=2;i<=sqrt((n-1)/1.0);i++)
			if((n-1)%i==0)
				a[j++]=i;
		for(i=--j;i>=0;i--)
		{
			long tmp=n;
			while(1)
			{
				tmp--;
				if(tmp%a[i]==0)
				{
					tmp=tmp/a[i]*(a[i]-1);
					if(tmp%a[i]==0) 
					{
						printf("%d coconuts, %d people and 1 monkey\n",n,a[i]);
						flag=1;
						goto elf;
					}
					if((tmp-1)%a[i]==0) continue;
					else break;
				}
			}
		}
elf:;
	if(flag==0) printf("%d coconuts, no solution\n",n);
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator