| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大家看看我怎么老是WA!! 测试数据都对了的!!郁闷之极啊#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator