Solution for Rosetta Code: Sailors, coconuts and a monkey problem

What is your hint or solution suggestion?
I am not sure how complicated the solution should be, but I got this algorithm from https://math.stackexchange.com/a/2349325

Solution 1
function splitCoconuts(intSailors) {
  var m = intSailors;
  if(m%2 == 1){
    var r = 1;
  }
  else{
    var r = m-1;
  }
  var n = r*(m**m) - m + 1;
  return n;
}

Challenge: Sailors, coconuts and a monkey problem

Link to the challenge: