Problem. sailors gather a pile of coconuts. During the night each sailor in turn divides the pile into equal parts with one left over (given to the monkey), hides one part, and puts the rest back. In the morning the remaining pile again divides into parts with one left over. Smallest initial pile?
Answer: ; for 5 sailors, .
long long coconuts(long long n) { // smallest pile: n sailors, each night one to the monkey then 1/n taken; morning split also leaves 1
long long p = 1; for (int i = 0; i <= n; i++) p *= n;
return p - n + 1;
}Proof: the smallest pile
Add “phantom” coconuts: if the pile satisfies , then is divisible by , and after one night step the new pile plus equals . So with , each of the divisions (n nights plus the morning) multiplies by and needs it to be a multiple of beforehand. Hence must be divisible by , and the smallest is , giving . Checked by brute-force simulation for .