Bananas for the monkey

Three friends go to the market on the back of their mules to buy a batch of bananas with the intention of distributing it the next day.

At night one of them got up, started counting the bananas, and made three parts. He took one of them and left the rest (two other parts). As after the deal he had a banana left over he gave it to the monkey.

Shortly after another king woke up and went to count the bananas to take his third part. After taking that amount and leaving the other two parts he saw that a banana was left over and gave it to the monkey.

Finally, almost at dawn, the third king got up without suspecting what his companions had done, took the third of the remaining bananas and as he saw that a banana was left over, he gave it to the monkey and went to bed.

The next morning they got up and no one confessed what he had been doing the previous night so they made the distribution of the bananas that were at that time, each took the third part and left over a banana they gave the monkey.

What is the smallest possible number of bananas to be able to make all the deals?

Solution

We define the following values:

E: Total number of bananas (What we want to find out).
D: Total bananas that the first friend stays when making the night cast
C: Total bananas that the second friend stays when making the night cast
B: Total bananas that the third friend stays when making the night cast
A: Last cast

The first friend distributes E - 1 bananas in three equal parts and remains a part that we call D so that D = (E-1) / 3 and leaves 2 × D bananas in the pile.

The second friend repeats the same operation with 2 × D-1 bananas as he delivers a banana to the monkey. Equivalent to the previous case, it takes a part for itself that we will call C = (2 × D - 1) / 3 and leaves two other parts, that is, 2 × C.

Finally, the last friend makes a new cast with the remaining bananas minus one that delivers to the monkey. So that each part we will call B = (2 × C - 1) / 3.

The next morning the remaining bananas minus one that is delivered to the monkey are distributed among the three. We will call each of the parts A = (2 × B - 1) / 3

If we put the equations together we have the following:
(81 × A + 65) / 8 = E

It is a diophantine equation in which its solutions are whole numbers.

In this case, the lowest possible number of bananas to be able to make all the deals is 79.

Thus:

- If we remove the banana from the monkey, the first friend took 78: 3 = 26 bananas and 79 - 1 - 26 = 52 remained.
- The second friend, after removing the banana from the monkey again, took 51: 3 = 17 and 52 - 1 - 17 = 34 bananas remained.
- The third friend, after delivering a banana to the monkey, took 33: 3 = 11 and left 34 - 1 - 11 = 22 bananas.
- so that in the morning cast they gave a banana to the monkey and the remaining 21 were distributed among the three, that is, 7 bananas.