Jump to navigation Jump to search
616 - Coconuts, Revisited
Just check all the numbers from sqrt(coconuts-1)+1 until 2. Essentially, you should check all the divisors of coconuts-1, from the higher to the lower.
- Integer variables should be enough.
- You must process 0s (answer: no solution).
25 30 3121 3 -1
25 coconuts, 3 people and 1 monkey 30 coconuts, no solution 3121 coconuts, 5 people and 1 monkey 3 coconuts, 2 people and 1 monkey