## 616 - Coconuts, Revisited

Moderator: Board moderators

wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

### 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

LTH
New poster
Posts: 12
Joined: Fri Feb 08, 2002 2:00 am
Location: Taiwan
Contact:
you just examine numbers from
ceil((double)sqrt(number of coconuts)) to 2

jichen
New poster
Posts: 1
Joined: Tue Feb 26, 2002 2:00 am
0 coconuts, no solution
1 coconuts, 1 people and 1 monkey
2000000000 coconuts, no solution
95 coconuts, no solution
2 coconuts, no solution
5 coconuts, no solution
11 coconuts, 2 people and 1 monkey

pochmann
New poster
Posts: 28
Joined: Sat Jan 26, 2002 2:00 am
Contact:
"1 coconuts, 1 people and 1 monkey"
"2000000000 coconuts, no solution"

How do you explain this? Why doesn't 2000000000 have the solution "1 people and 1 monkey", just like 1? I think you're inconsistent.

Stefan

pochmann
New poster
Posts: 28
Joined: Sat Jan 26, 2002 2:00 am
Contact:
Yep, I got it accepted, although I say "1 coconuts, no solution".

Stefan

pochmann
New poster
Posts: 28
Joined: Sat Jan 26, 2002 2:00 am
Contact:
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

Rossi
New poster
Posts: 20
Joined: Thu Mar 21, 2002 2:00 am
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;
}

ram
New poster
Posts: 30
Joined: Wed Mar 06, 2002 2:00 am
Contact:
"long int" is not sufficient for longer values.

Try using "long double" instead of "long int" and "fmod" instead of "%".

Betovsky
New poster
Posts: 26
Joined: Wed Jun 05, 2002 7:30 pm
Location: Portugal
lol

the right solution for 1 coco is that there isnt solution.

shouldnt be 1 man and 1 monkey...

or to disable this confusion shouldnt the input for the num of cocos
begin in 2 ...

just my thoughts...

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Contact:

### 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

Andrey Mokhov
Experienced poster
Posts: 128
Joined: Fri Nov 15, 2002 7:45 am
Location: Kyrgyzstan
You're wrong.

Think of it - output:

Code: Select all

``823537 coconuts, 7 people and 1 monkey``
Good luck!

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Contact:
Thanx!
i was really confusing. Can u supply me the highes number
of people in the input limit?
Once again thanx!

Andrey Mokhov
Experienced poster
Posts: 128
Joined: Fri Nov 15, 2002 7:45 am
Location: Kyrgyzstan
Well you know I was lazy enough to calculate the higher limit of n, but it's clear for me that n=30 is enough. Of course it may be even too much, but I don't want to improve the limit.

Best regards.

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:
please any 1 tell me the algorithm that may be used to solved the prob.
i get myself used to tle for the prob.