10726 - Coco Monkey
Moderator: Board moderators
10726 - Coco Monkey
I AC for this problem but my algorithm is slow. In ranklist for this problem i saw results 0.000 seconds. Is there exist analitical solution? I.e. simple equation?
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Yes in both cases. The only thing that matters is that every sailor gets M coconuts left after dividing the coconuts evenly in the S baskets (even if he gets 0 coconuts in each basket).little joey wrote:- for 2 sailors and no monkeys, is 0 coconuts acceptable?
- for 2 sailors and one monkey, is 3 coconuts acceptable?
can anyone explain case2 and case3?
in case 1, i can understand what it means..
but case 2: 10 -> means S=4 M=2 C=5+10=15, right?
15/4=3...3 left 9.. but 3!=M...
C should be 506, isn't it?
506/4=126...2 left 378
378/4=94.....2 left 282
282/4=70.....2 left 210
210/4=52.....2 left 156
156/4=39.....0
in case 3: 357, means S=6 M=4 C=1+357=358
358/6=59....4 left 295
295/6=49....1 <-- 1!=M
do i misunderstand this problem? can somebody teach me.. thx..
in case 1, i can understand what it means..
but case 2: 10 -> means S=4 M=2 C=5+10=15, right?
15/4=3...3 left 9.. but 3!=M...
C should be 506, isn't it?
506/4=126...2 left 378
378/4=94.....2 left 282
282/4=70.....2 left 210
210/4=52.....2 left 156
156/4=39.....0
in case 3: 357, means S=6 M=4 C=1+357=358
358/6=59....4 left 295
295/6=49....1 <-- 1!=M
do i misunderstand this problem? can somebody teach me.. thx..
Observe that if C is a solution, then C + S^(S+1) is also a solution.lonelyone wrote:What's the analytical solution
Any hint in detail, please..
So the solutions can be computed mod S^(S+1)
So generally, the solution are of the form S^(S+1)*a + b, where a,b are non-negative integers.
The key is to find out what b is.
Hint: b can be written in terms of S and M and it depends on the parity of S.