UVa 616 - Coconuts, Revisited

Explanation
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

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

Input
25 30 3121 3 -1

Output
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