| ||||||||||
| 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 <stdio.h>
#include <math.h>
int main() {
int i,j,k,num,max,n;
while(1) {
scanf("%d",&num);
if(num<0)break;
if(num==0){printf("0 coconuts, 0 people and 1 monkey\n");continue;}
max=0;
k=(int)sqrt(1.0*num);
for(i=2;i<=k;i++) {
n=num;
for(j=0;j<i;j++) {
if(n%i!=1) break;
n=n-1-n/i;
}
if(j>=i && n%i==0)max=i;
}
printf("%d coconuts, ",num);
if(max==0) printf("no solution\n");
else printf("%d people and 1 monkey\n",max);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator