The monkey and the coconuts

The monkey and the coconuts is a mathematical puzzle in the field of Diophantine analysis that originated in a short story involving five sailors and a monkey on a desert island who divide up a pile of coconuts; the problem is to find the number of coconuts in the original pile (fractional coconuts not allowed). The problem is notorious for its confounding difficulty to unsophisticated puzzle solvers, though with the proper mathematical approach, the solution is trivial. The problem has become a staple in recreational mathematics collections.

General description
The problem can be expressed as:


 * There is a pile of coconuts, owned by five men. One man divides the pile into five equal piles, giving the one left over coconut to a passing monkey, and takes away his own share. The second man then repeats the procedure, dividing the remaining pile into five and taking away his share, as do the third, fourth, and fifth, each of them finding one coconut left over when dividing the pile by five, and giving it to a monkey. Finally, the group divide the remaining coconuts into five equal piles: this time no coconuts are left over.
 * How many coconuts were there in the original pile?

The monkey and the coconuts is the best known representative of a class of puzzle problems requiring integer solutions structured as recursive division or fractionating of some discretely divisible quantity, with or without remainders, and a final division into some number of equal parts, possibly with a remainder. The problem is so well known that the entire class is often referred to broadly as "monkey and coconut type problems", though most are not closely related to the problem.

Another example: "I have a whole number of pounds of cement, I know not how many, but after addition of a ninth and an eleventh, it was partitioned into 3 sacks, each with a whole number of pounds. How many pounds of cement did I have?"

Problems ask for either the initial or terminal quantity. Stated or implied is the smallest positive number that could be a solution. There are two unknowns in such problems, the initial number and the terminal number, but only one equation which is an algebraic reduction of an expression for the relation between them. Common to the class is the nature of the resulting equation, which is a linear Diophantine equation in two unknowns. Most members of the class are determinate, but some are not (the monkey and the coconuts is one of the latter). Familiar algebraic methods are unavailing for solving such equations.

History
The origin of the class of such problems has been attributed to the Indian mathematician Mahāvīra in chapter VI, § 131$1/2$, 132$1/2$ of his Ganita-sara-sangraha (“Compendium of the Essence of Mathematics”), circa 850CE, which dealt with serial division of fruit and flowers with specified remainders. That would make progenitor problems over 1000 years old before their resurgence in the modern era. Problems involving division which invoke the Chinese remainder theorem appeared in Chinese literature as early as the first century CE. Sun Tzu asked: Find a number which leaves the remainders 2, 3 and 2 when divided by 3, 5 and 7, respectively. Diophantus of Alexandria first studied problems requiring integer solutions in the 3rd century CE. The Euclidean algorithm for greatest common divisor which underlies the solution of such problems was discovered by the Greek geometer Euclid and published in his Elements in 300CE.

Prof. David Singmaster, a historian of puzzles, traces a series of less plausibly related problems through the middle ages, with a few references as far back as the Babylonian empire circa 1700 BC. They involve the general theme of adding or subtracting fractions of a pile or specific numbers of discrete objects and asking how many there could have been in the beginning. The next reference to a similar problem is in Jacques Ozanam's Récréations mathématiques et physiques, 1725. In the realm of pure mathematics, Lagrange in 1770 expounded his continued fraction theorem and applied it to solution of Diophantine equations.

The first description of the problem in close to its modern wording appears in Lewis Carroll's diaries in 1888: it involves a pile of nuts on a table serially divided by four brothers, each time with remainder of one given to a monkey, and the final division coming out even. The problem never appeared in any of Carroll's published works, though from other references it appears the problem was in circulation in 1888. An almost identical problem appeared in W.W. Rouse Ball's Elementary Algebra (1890). The problem was mentioned in works of period mathematicians, with solutions, mostly wrong, indicating that the problem was new and unfamiliar at the time.

The problem became notorious when American novelist and short story writer Ben Ames Williams modified an older problem and included it in a story, "Coconuts", in the October 9, 1926, issue of the Saturday Evening Post. Here is how the problem was stated by Williams (condensed and paraphrased):


 * Five men and a monkey were shipwrecked on an island. They spent the first day gathering coconuts for food.


 * During the night, one man woke up, and decided to take his share early. So he divided the coconuts in five piles. He had one coconut left over, and he gave that to the monkey. Then he hid his pile and put the rest back together.


 * By and by each of the five men woke up and did the same thing, one after the other: each one taking a fifth of the coconuts that were in the pile when he woke up, and having one left over for the monkey. In the morning they divided what coconuts were left, and they came out in five equal shares. Of course each one must have known there were coconuts missing; but each one was guilty as the others, so they didn't say anything.


 * How many coconuts were there in the original pile?

Williams had not included an answer in the story. The magazine was inundated by more than 2,000 letters pleading for an answer to the problem. The Post editor, Horace Lorimer, famously fired off a telegram to Williams saying: "FOR THE LOVE OF MIKE, HOW MANY COCONUTS? HELL POPPING AROUND HERE". Williams continued to get letters asking for a solution or proposing new ones for the next twenty years.

Martin Gardner featured the problem in his April 1958 Mathematical Games column in Scientific American. According to Gardner, Williams had modified an older problem to make it more confounding. In the older version there is a coconut for the monkey on the final division; in Williams's version the final division in the morning comes out even. But the available historical evidence does not indicate which versions Williams had access to. Gardner once told his son Jim that it was his favorite problem. He said that the Monkey and the Coconuts is "probably the most worked on and least often solved" Diophantine puzzle. Since that time the Williams version of the problem has become a staple of recreational mathematics. The original story containing the problem was reprinted in full in Clifton Fadiman's 1962 anthology The Mathematical Magpie, a book that the Mathematical Association of America recommends for acquisition by undergraduate mathematics libraries.

Numerous variants which vary the number of sailors, monkeys, or coconuts have appeared in the literature.

Solutions
Numerous solutions starting as early as 1928 have been published both for the original problem and Williams modification.

Before entering upon a solution to the problem, a couple of things may be noted. If there were no remainders, given there are 6 divisions of 5, 56=15,625 coconuts must be in the pile; on the 6th and last division, each sailor receives 1024 coconuts. No smaller positive number will result in all 6 divisions coming out even. That means that in the problem as stated, any multiple of 15,625 may be added to the pile, and it will satisfy the problem conditions. That also means that the number of coconuts in the original pile is smaller than 15,625, else subtracting 15,625 will yield a smaller solution. But the number in the original pile is not trivially small, like 5 or 10 (that is why this is a hard problem) – it may be in the hundreds or thousands. Unlike trial and error in the case of guessing a polynomial root, trial and error for a Diophantine root will not result in any obvious convergence. There is no simple way of estimating what the solution will be.

The original version


Martin Gardner's 1958 Mathematical Games column begins its analysis by solving the original problem (with one coconut also remaining in the morning) because it is easier than Williams's version. Let F be the number of coconuts received by each sailor after the final division into 5 equal shares in the morning. Then the number of coconuts left before the morning division is $$5F+1$$; the number present when the fifth sailor awoke was $$\tfrac{5}{4}(5F+1)+1 = \tfrac{25}{4}F+\tfrac{9}{4}$$; the number present when the fourth sailor awoke was $$\tfrac{5}{4}(\tfrac{25}{4}F+\tfrac{9}{4})+1 = \tfrac{125}{16}F+\tfrac{241}{16}$$; and so on. We find that the size N of the original pile satisfies the Diophantine equation
 * $$1024N = 15625F + 11529$$

Gardner points out that this equation is "much too difficult to solve by trial and error," but presents a solution he credits to J. H. C. Whitehead (via Paul Dirac): The equation also has solutions in negative integers. Trying out a few small negative numbers it turns out $$N = -4, F = -1$$ is a solution. We add 15625 to N and 1024 to F to get the smallest positive solution: $$N = 15621, F = 1023$$.

Williams version


Trial and error fails to solve Williams's version, so a more systematic approach is needed.

Using a sieve
The search space can be reduced by a series of increasingly larger factors by observing the structure of the problem so that a bit of trial and error finds the solution. The search space is much smaller if one starts with the number of coconuts received by each man in the morning division, because that number is much smaller than the number in the original pile.

If F is the number of coconuts each sailor receives in the final division in the morning, the pile in the morning is 5F, which must also be divisible by 4, since the last sailor in the night combined 4 piles for the morning division. So the morning pile, call the number n, is a multiple of 20. The pile before the last sailor woke up must have been 5/4(n)+1. If only one sailor woke up in the night, then 5/4(20)+1 = 26 works for the minimum number of coconuts in the original pile. But if two sailors woke up, 26 is not divisible by 4, so the morning pile must be some multiple of 20 that yields a pile divisible by 4 before the last sailor wakes up. It so happens that 3*20=60 works for two sailors: applying the recursion formula for n twice yields 96 as the smallest number of coconuts in the original pile. 96 is divisible by 4 once more, so for 3 sailors awakening, the pile could have been 121 coconuts. But 121 is not divisible by 4, so for 4 sailors awakening, one needs to make another leap. At this point, the analogy becomes obtuse, because in order to accommodate 4 sailors awakening, the morning pile must be some multiple of 60: if one is persistent, it may be discovered that 17*60=1020 does the trick and the minimum number in the original pile would be 2496. A last iteration on 2496 for 5 sailors awakening, i.e. 5/4(2496)+1 brings the original pile to 3121 coconuts.

Blue coconuts
Another device is to use extra objects to clarify the division process. Suppose that in the evening we add four blue coconuts to the pile. Then the first sailor to wake up will find the pile to be evenly divisible by five, instead of having one coconut left over. The sailor divides the pile into fifths such that each blue coconut is in a different fifth; then he takes the fifth with no blue coconut, gives one of his coconuts to the monkey, and puts the other four fifths (including all four blue coconuts) back together. Each sailor does the same. During the final division in the morning, the blue coconuts are left on the side, belonging to no one. Since the whole pile was evenly divided 5 times in the night, it must have contained 55 coconuts: 4 blue coconuts and 3121 ordinary coconuts.

The device of using additional objects to aid in conceptualizing a division appeared as far back as 1912 in a solution due to Norman H. Anning.

A related device appears in the 17-animal inheritance puzzle: A man wills 17 horses to his three sons, specifying that the eldest son gets half, the next son one-third, and the youngest son, one-ninth of the animals. The sons are confounded, so they consult a wise horse trader. He says, "here, borrow my horse." The sons duly divide the horses, discovering that all the divisions come out even, with one horse left over, which they return to the trader.

Base 5 numbering
A simple solution appears when the divisions and subtractions are performed in base 5. Consider the subtraction, when the first sailor takes his share (and the monkey's). Let n0,n1,... represent the digits of N, the number of coconuts in the original pile, and s0,s1... represent the digits of the sailor's share S, both base 5. After the monkey's share, the least significant digit of N must now be 0; after the subtraction, the least significant digit of N' left by the first sailor must be 1, hence the following (the actual number of digits in N as well as S is unknown, but they are irrelevant just now):

n5n4n3n2n1 0  (N5) s4s3s2s1s0  (S5) 1  (N'5) The digit subtracted from 0 base 5 to yield 1 is 4, so s0=4. But since S is (N-1)/5, and dividing by 55 is just shifting the number right one position, n1=s0=4. So now the subtraction looks like:

n5n4n3n2 4 0 s4s3s2s1 4 1

Since the next sailor is going to do the same thing on N', the least significant digit of N' becomes 0 after tossing one to the monkey, and the LSD of S' must be 4 for the same reason; the next digit of N' must also be 4. So now it looks like:

n5n4n3n2 4 0 s4s3s2s1 4 4 1

Borrowing 1 from n1 (which is now 4) leaves 3, so s1 must be 4, and therefore n2 as well. So now it looks like:

n5n4n3 4 4 0 s4s3s2 4 4 4 1

But the same reasoning again applies to N' as applied to N, so the next digit of N' is 4, so s2 and n3 are also 4, etc. There are 5 divisions; the first four must leave an odd number base 5 in the pile for the next division, but the last division must leave an even number base 5 so the morning division will come out even (in 5s). So there are four 4s in N following a LSD of 1: N=444415=312110

A numerical approach
A straightforward numeric analysis goes like this: If N is the initial number, each of 5 sailors transitions the original pile thus:
 * N => 4(N–1)/5 or equivalently, N => 4(N+4)/5 – 4.

Repeating this transition 5 times gives the number left in the morning:
 * N => 4(N+4)/5 – 4
 * => 16(N+4)/25 – 4
 * => 64(N+4)/125 – 4
 * => 256(N+4)/625 – 4
 * => 1024(N+4)/3125 – 4

Since that number must be an integer and 1024 is relatively prime to 3125, N+4 must be a multiple of 3125. The smallest such multiple is 3125·1, so N = 3125 – 4 = 3121; the number left in the morning comes to 1020, which is evenly divisible by 5 as required.

Modulo congruence
A simple succinct solution can be obtained by directly utilizing the recursive structure of the problem: There were five divisions of the coconuts into fifths, each time with one left over (putting aside the final division in the morning). The pile remaining after each division must contain an integral number of coconuts. If there were only one such division, then it is readily apparent that 5·1+1=6 is a solution. In fact any multiple of five plus one is a solution, so a possible general formula is 5·k – 4, since a multiple of 5 plus 1 is also a multiple of 5 minus 4. So 11, 16, etc also work for one division.

If two divisions are done, a multiple of 5·5=25 rather than 5 must be used, because 25 can be divided by 5 twice. So the number of coconuts that could be in the pile is k·25 – 4. k=1 yielding 21 is the smallest positive number that can be successively divided by 5 twice with remainder 1. If there are 5 divisions, then multiples of 55=3125 are required; the smallest such number is 3125 – 4 = 3121. After 5 divisions, there are 1020 coconuts left over, a number divisible by 5 as required by the problem. In fact, after n divisions, it can be proven that the remaining pile is divisible by n, a property made convenient use of by the creator of the problem.

A formal way of stating the above argument is:

The original pile of coconuts will be divided by 5 a total of 5 times with a remainder of 1, not considering the last division in the morning. Let N = number of coconuts in the original pile. Each division must leave the number of nuts in the same congruence class (mod 5). So,


 * $$N \equiv 4/5\cdot(N-1)$$ (mod 5) (the –1 is the nut tossed to the monkey)
 * $$5N \equiv 4N - 4 $$ (mod 5)
 * $$N \equiv -4$$ (mod 5) (–4 is the congruence class)

So if we began in modulo class –4 nuts then we will remain in modulo class –4. Since ultimately we have to divide the pile 5 times or 5^5, the original pile was 5^5 – 4 = 3121 coconuts. The remainder of 1020 coconuts conveniently divides evenly by 5 in the morning. This solution essentially reverses how the problem was (probably) constructed.

The Diophantine equation and forms of solution
The equivalent Diophantine equation for this version is:
 * $$1024N=15625F+8404$$ (1)

where N is the original number of coconuts, and F is the number received by each sailor on the final division in the morning. This is only trivially different than the equation above for the predecessor problem, and solvability is guaranteed by the same reasoning.

Reordering,
 * $$1024N-15625F=8404$$ (2)

This Diophantine equation has a solution which follows directly from the Euclidean algorithm; in fact, it has infinitely many periodic solutions positive and negative. If (x0, y0) is a solution of 1024x–15625y=1, then N0=x0·8404, F0=y0·8404 is a solution of (2), which means any solution must have the form


 * $$ \begin{cases}

N=N_0 + 15625\cdot t \\ F=F_0 + 1024\cdot t \end{cases}$$(3)

where $$t$$ is an arbitrary parameter that can have any integral value.

A reductionist approach
One can take both sides of (1) above modulo 1024, so
 * $$1024N=15625F+8404 \mod 1024$$

Another way of thinking about it is that in order for $$n$$ to be an integer, the RHS of the equation must be an integral multiple of 1024; that property will be unaltered by factoring out as many multiples of 1024 as possible from the RHS. Reducing both sides by multiples of 1024,
 * $$0=(15625F-15\cdot 1024F)+(8404-8\cdot 1024) \mod 1024$$

subtracting,
 * $$0=265F+212 \mod 1024$$

factoring,
 * $$0=53 \cdot(5F+4) \mod 1024$$

The RHS must still be a multiple of 1024; since 53 is relatively prime to 1024, 5F+4 must be a multiple of 1024. The smallest such multiple is 1·1024, so 5F+4=1024 and F=204. Substituting into (1)
 * $$1024N=15625\cdot 204+8404 \Rightarrow N=\frac{3 195 904}{1024} \Rightarrow N=3121$$

Euclidean algorithm
The Euclidean algorithm is quite tedious but a general methodology for solving rational equations ax+by=c requiring integral answers. From (2) above, it is evident that 1024 (210) and 15625 (56) are relatively prime and therefore their GCD is 1, but we need the reduction equations for back substitution to obtain N and F in terms of these two quantities:

First, obtain successive remainders until GCD remains:

15625 = 15·1024 + 265 (a)

1024 = 3·265 + 229 (b)

265 = 1·229 + 36 (c)

229 = 6·36 + 13 (d)

36 = 2·13 + 10 (e)

13 = 1·10 + 3 (f)

10 = 3·3 + 1 (g) (remainder 1 is GCD of 15625 and 1024)

1 = 10 – 3(13–1·10) = 4·10 – 3·13 (reorder (g), substitute for 3 from (f) and combine)

1 = 4·(36 – 2·13) – 3·13 = 4·36 – 11·13 (substitute for 10 from (e) and combine)

1 = 4·36 – 11·(229 – 6·36) = –11·229 + 70*36 (substitute for 13 from (d) and combine)

1 = –11·229 + 70·(265 – 1·229) = –81·229 + 70·265 (substitute for 36 from (c) and combine)

1 = –81·(1024 – 3·265) + 70·265 = –81·1024 + 313·265 (substitute for 229 from (b) and combine)

1 = –81·1024 + 313·(15625 – 15·1024) = 313·15625 – 4776·1024 (substitute for 265 from (a) and combine)

So the pair (N0,F0) = (-4776·8404, -313*8404); the smallest $$t$$ (see (3) in the previous subsection) that will make both N and F positive is 2569, so:


 * $$ N = N_0 + 15625\cdot 2569 = 3121$$
 * $$ F = F_0 + 1024\cdot 2569 = 204$$

Continued fraction
Alternately, one may use a continued fraction, whose construction is based on the Euclidean algorithm. The continued fraction for $1024/15625$ (0.065536 exactly) is [;15,3,1,6,2,1,$\overline{3}$]; its convergent terminated after the repetend is $313/4776$, giving us x0=–4776 and y0=313. The least value of t for which both N and F are non-negative is 2569, so
 * $$N= -4776 \cdot 8404+15625 \cdot 2569=3121$$.

This is the smallest positive number that satisfies the conditions of the problem.

A generalized solution
When the number of sailors is a parameter, let it be $$m$$, rather than a computational value, careful algebraic reduction of the relation between the number of coconuts in the original pile and the number allotted to each sailor in the morning yields an analogous Diophantine relation whose coefficients are expressions in $$m$$.

The first step is to obtain an algebraic expansion of the recurrence relation corresponding to each sailor's transformation of the pile, $$n_i$$ being the number left by the sailor:
 * $$n_i = \frac{m-1}{m}(n_{i-1}-1)$$

where $$n_{i\rightarrow 0} \equiv N$$, the number originally gathered, and $$n_{i\rightarrow m}$$ the number left in the morning. Expanding the recurrence by substituting $$n_i$$ for $$n_{i-1}$$ $$m$$ times yields:
 * $$n_m=\left(\frac{m-1}{m}\right)^m\cdot n_0 - \left[(\frac{m-1}{m})^m+...+(\frac{m-1}{m})^2+\frac{m-1}{m}\right]$$

Factoring the latter term,
 * $$n_m=\left(\frac{m-1}{m}\right)^m\cdot n_0 - \left(\frac{m-1}{m}\right)\cdot \left[(\frac{m-1}{m})^{m-1}+...+\frac{m-1}{m}+1\right]$$

The power series polynomial in brackets of the form $$x^{m-1}+...+x+1$$ sums to $$(1-x^m)/(1-x)$$ so,
 * $$n_m=\left(\frac{m-1}{m}\right)^m\cdot n_0 - \left(\frac{m-1}{m}\right)\cdot \left[\left(1-(\frac{m-1}{m})^m\right)\bigg/\left(1-(\frac{m-1}{m})\right)\right]$$

which simplifies to:
 * $$n_m=\left(\frac{m-1}{m}\right)^m\cdot n_0 - (m-1)\cdot \frac{m^m - (m-1)^m}{m^m}$$

But $$n_m$$ is the number left in the morning which is a multiple of $$m$$ (i.e. $$F$$, the number allotted to each sailor in the morning):
 * $$m\cdot F = \left(\frac{m-1}{m}\right)^m\cdot n_0 - (m-1)\cdot \frac{m^m - (m-1)^m}{m^m}$$

Solving for $$n_0$$(=$$N$$),
 * $$N=m^m\cdot \frac{m-1+m\cdot F}{(m-1)^m} - (m-1)$$

The equation is a linear Diophantine equation in two variables, $$N$$ and $$F$$. $$m$$ is a parameter that can be any integer. The nature of the equation and the method of its solution do not depend on $$m$$.

Number theoretic considerations now apply. For $$N$$ to be an integer, it is sufficient that $$\frac{m-1+m\cdot F}{(m-1)^m}$$ be an integer, so let it be $$r$$:
 * $$r=\frac{m-1+m\cdot F}{(m-1)^m}$$

The equation must be transformed into the form $$ax+by=\pm 1$$ whose solutions are formulaic. Hence:
 * $$(m-1)^m\cdot r - m\cdot s = -1$$, where $$s = 1+F$$

Because $$m$$ and $$m-1$$ are relatively prime, there exist integer solutions $$(r,s)$$ by Bézout's identity. This equation can be restated as:
 * $$(m-1)^m\cdot r\equiv -1\mod m$$

But (m–1)m is a polynomial Z·m–1 if m is odd and Z·m+1 if m is even, where Z is a polynomial with monomial basis in m. Therefore r0=1 if m is odd and r0=–1 if m is even is a solution.

Bézout's identity gives the periodic solution $$r=r_0+k\cdot m$$, so substituting for $$r$$ in the Diophantine equation and rearranging:
 * $$N=r_0\cdot m^m - (m-1) + k\cdot m^{m+1}$$

where $$r_0=1$$ for $$m$$ odd and $$r_0=-1$$ for $$m$$ even and $$k$$ is any integer. For a given $$m$$, the smallest positive $$k$$ will be chosen such that $$N$$ satisfies the constraints of the problem statement.

In the William's version of the problem, $$m$$ is 5 sailors, so $$r_0$$ is 1, and $$k$$ may be taken to be zero to obtain the lowest positive answer, so N = 1 · 55 – 4 = 3121 for the number of coconuts in the original pile. (It may be noted that the next sequential solution of the equation for k=–1, is –12504, so trial and error around zero will not solve the Williams version of the problem, unlike the original version whose equation, fortuitously, had a small magnitude negative solution).

Here is a table of the positive solutions $$N$$ for the first few $$m$$ ($$k$$ is any non-negative integer):

Other variants and general solutions
Other variants, including the putative predecessor problem, have related general solutions for an arbitrary number of sailors.

When the morning division also has a remainder of one, the solution is:
 * $$N=- (m-1) + k\cdot m^{m+1}$$

For $$m=5$$ and $$k=1$$ this yields 15,621 as the smallest positive number of coconuts for the pre-William's version of the problem.

In some earlier alternate forms of the problem, the divisions came out even, and nuts (or items) were allocated from the remaining pile after division. In these forms, the recursion relation is:
 * $$n_i = \frac{m-1}{m}n_{i-1}-1$$

The alternate form also had two endings, when the morning division comes out even, and when there is one nut left over for the monkey. When the morning division comes out even, the general solution reduces via a similar derivation to:
 * $$N=-m + k\cdot m^{m+1}$$

For example, when $$m=4$$ and $$k=1$$, the original pile has 1020 coconuts, and after four successive even divisions in the night with a coconut allocated to the monkey after each division, there are 80 coconuts left over in the morning, so the final division comes out even with no coconut left over.

When the morning division results in a nut left over, the general solution is:
 * $$N=r_0\cdot m^m - m + k\cdot m^{m+1}$$

where $$r_0=-1$$ if $$m$$ is odd, and $$r_0=1$$ if $$m$$ is even. For example, when $$m=3$$, $$r_0=-1$$ and $$k=1$$, the original pile has 51 coconuts, and after three successive divisions in the night with a coconut allocated to the monkey after each division, there are 13 coconuts left over in the morning, so the final division has a coconut left over for the monkey.

Other post-Williams variants which specify different remainders including positive ones (i.e. the monkey adds coconuts to the pile), have been treated in the literature. The solution is:
 * $$N=r_0\cdot m^m - c \cdot(m-1) + k\cdot m^{m+1}$$

where $$r_0=1$$ for $$m$$ odd and $$r_0=-1$$ for $$m$$ even, $$c$$ is the remainder after each division (or number of monkeys) and $$k$$ is any integer ($$c$$ is negative if the monkeys add coconuts to the pile).

Other variants in which the number of men or the remainders vary between divisions, are generally outside the class of problems associated with the monkey and the coconuts, though these similarly reduce to linear Diophantine equations in two variables. Their solutions yield to the same techniques and present no new difficulties.