Sailors, coconuts and a monkey problem
Solutions
Solution 1 (Click to Show/Hide)
function splitCoconuts(n) {
// https://oeis.org/A002021
return n % 2 === 0 ?
(n - 1) * (n**n - 1) :
n**n - n + 1;
}
function splitCoconuts(n) {
// https://oeis.org/A002021
return n % 2 === 0 ?
(n - 1) * (n**n - 1) :
n**n - n + 1;
}