616 - Coconuts, Revisited

All about problems in Volume 6. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

616 - Coconuts, Revisited

Post by wyvmak »

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:

Post by LTH »

you just examine numbers from
ceil((double)sqrt(number of coconuts)) to 2
:smile:
jichen
New poster
Posts: 1
Joined: Tue Feb 26, 2002 2:00 am

Post by jichen »

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:

Post by pochmann »

"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:

Post by pochmann »

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:

Post by pochmann »

Btw, you can find the solution to this problem in the American Mathematical Monthly of the year 1928 :wink: 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
Location: Bangladesh

Post by Rossi »

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:

Post by ram »

"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

Post by Betovsky »

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
Location: BANGLADESH
Contact:

616

Post by Jalal »

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? :roll:
if it tru than all the number grater 3121 should give the followin output:
n coconuts, no solution
:cry:
Andrey Mokhov
Experienced poster
Posts: 128
Joined: Fri Nov 15, 2002 7:45 am
Location: Kyrgyzstan

Post by Andrey Mokhov »

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
Location: BANGLADESH
Contact:

Post by Jalal »

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

Post by Andrey Mokhov »

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. :lol:

Best regards.
anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam »

please any 1 tell me the algorithm that may be used to solved the prob.
i get myself used to tle for the prob.
please help. :oops: :oops:
"Everything should be made simple, but not always simpler"
kmhasan
Problemsetter
Posts: 107
Joined: Fri Oct 26, 2001 2:00 am
Location: Canada
Contact:

Post by kmhasan »

simulate in range sqrt(coconuts)+1 down to 2.
Post Reply

Return to “Volume 6 (600-699)”