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 fxlbest at 2005-11-11 22:07:27 on Problem 1309
#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:
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