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 » Tue Jan 01, 2002 10:58 am

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 » Mon Feb 11, 2002 5:37 pm

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 » Tue Feb 26, 2002 3:03 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:

Post by pochmann » Tue Feb 26, 2002 1:03 pm

"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 » Tue Feb 26, 2002 1:38 pm

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 » Thu Feb 28, 2002 5:26 am

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 » Thu Mar 21, 2002 8:55 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:

Post by ram » Mon Apr 01, 2002 8:52 am

"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 » Thu Jun 06, 2002 7:41 pm

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 » Fri Dec 27, 2002 8:08 am

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 » Fri Dec 27, 2002 9:09 am

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 » Fri Dec 27, 2002 11:01 am

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 » Mon Dec 30, 2002 10:06 am

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 » Mon Dec 30, 2002 11:00 pm

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"

User avatar
kmhasan
Problemsetter
Posts: 107
Joined: Fri Oct 26, 2001 2:00 am
Location: Canada
Contact:

Post by kmhasan » Tue Dec 31, 2002 8:27 pm

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

Post Reply

Return to “Volume 6 (600-699)”