UVa 616

From Algorithmist
Jump to navigation Jump to search

616 - Coconuts, Revisited[edit]

Explanation[edit]

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.

Gotchas[edit]

  • Integer variables should be enough.
  • You must process 0s (answer: no solution).

Input[edit]

25
30
3121
3
-1

Output[edit]

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