616 - Coconuts, Revisited
Moderator: Board moderators
616 - Coconuts, Revisited
can anyone tell me the trick? pls help me to verify the following cases.
Input:
0
1
2000000000
95
2
5
11
-1
Output:
0 coconuts, no solution
1 coconuts, no solution
2000000000 coconuts, no solution
95 coconuts, no solution
2 coconuts, no solution
5 coconuts, no solution
11 coconuts, 2 people and 1 monkey
Input:
0
1
2000000000
95
2
5
11
-1
Output:
0 coconuts, no solution
1 coconuts, no solution
2000000000 coconuts, no solution
95 coconuts, no solution
2 coconuts, no solution
5 coconuts, no solution
11 coconuts, 2 people and 1 monkey
Btw, you can find the solution to this problem in the American Mathematical Monthly of the year 1928
Too bad, fully solved 74 years ago...
How did I find out? Well, you might see a pattern in the solutions. And then the website http://www.research.att.com/~njas/sequences/ was really helpful.
Stefan
![:wink:](./images/smilies/icon_wink.gif)
How did I find out? Well, you might see a pattern in the solutions. And then the website http://www.research.att.com/~njas/sequences/ was really helpful.
Stefan
why it is wrong....i can't find anything
#include<stdio.h>
#include<math.h>
int check(long int,long int);
int main(void)
{
register long int i;
long int num;
double logged;
while(1){
scanf("%ld",&num);
if(num<0)
break;
for(i=ceil((double)sqrt(num));i>=2;i--){
if(check(i,num))
break;
}
if(i<2)
printf("%ld coconuts, no solutionn",num);
else
printf("%ld coconuts, %ld people and 1 monkeyn",num,i);
}
return 0;
}
int check(long int chk,long int coco)
{
register long int i;
long int mod;
for(i=0;i<chk;i++){
mod=coco%chk;
if(mod!=1)
break;
coco-=((coco/chk)+mod);
if(coco==0)
break;
}
return (i==chk&&coco%chk==0)?1:0;
}
#include<stdio.h>
#include<math.h>
int check(long int,long int);
int main(void)
{
register long int i;
long int num;
double logged;
while(1){
scanf("%ld",&num);
if(num<0)
break;
for(i=ceil((double)sqrt(num));i>=2;i--){
if(check(i,num))
break;
}
if(i<2)
printf("%ld coconuts, no solutionn",num);
else
printf("%ld coconuts, %ld people and 1 monkeyn",num,i);
}
return 0;
}
int check(long int chk,long int coco)
{
register long int i;
long int mod;
for(i=0;i<chk;i++){
mod=coco%chk;
if(mod!=1)
break;
coco-=((coco/chk)+mod);
if(coco==0)
break;
}
return (i==chk&&coco%chk==0)?1:0;
}
616
I think its not possible for 616(coconuts-prob)
its not possible to get the number of people and monket
if the the input is greater than 3121.
is my concept is true?
if it tru than all the number grater 3121 should give the followin output:
n coconuts, no solution
![:cry:](./images/smilies/icon_cry.gif)
its not possible to get the number of people and monket
if the the input is greater than 3121.
is my concept is true?
![:roll:](./images/smilies/icon_rolleyes.gif)
if it tru than all the number grater 3121 should give the followin output:
n coconuts, no solution
![:cry:](./images/smilies/icon_cry.gif)
-
- Experienced poster
- Posts: 128
- Joined: Fri Nov 15, 2002 7:45 am
- Location: Kyrgyzstan
You're wrong.
Think of it - output:
Good luck!
![:(](./images/smilies/icon_frown.gif)
Think of it - output:
Code: Select all
823537 coconuts, 7 people and 1 monkey
-
- Experienced poster
- Posts: 128
- Joined: Fri Nov 15, 2002 7:45 am
- Location: Kyrgyzstan