# The Pirates and the Mangoes [duplicate]

A group of hardy pirates are sailing along when they encounter the Royal Navy of Lord Richard. The battle is long and vicious. Sadly, the pirate ship is sunk. The only survivors are five of the crew and the captain's foul-mouthed parrot. The lot make it to a tiny island nearby in time to watch the Navy's vessel disappear over the horizon. Disheartened but determined to survive, the 5 crewman go foraging. The only food they are able to gather is a collection of mangoes. (They're terrible hunters and fisherman.) The parrot finds some nuts but it's not sharing. The pirates pile up all their mangoes and go to sleep.

Some time in the night, one of the crew wake up. Worried that he won't get his fair share in the morning - pirates are so rude, after all - he divides the big pile into 5 smaller piles. There's one left over, so he tosses it to the parrot. He hides one of the smaller piles, rolls the rest back into a single pile, and goes to sleep.

After the first pirate has fallen asleep, a second pirate wake up. He, too, is worried about getting his fair share. Being of the same mindset of the first to awake, the second pirate also divides the big pile (actually, it's what's left of the original pile after the first got done with it but the second doesn't know that) into 5 smaller piles. Again, there's one left over so he tosses it to the parrot. He hides his pile, rolls the rest back together, and goes to bed.

This repeats for every pirate. Each divides what's left into 5 piles, gives the 1 leftover to the parrot, hides their pile, and rolls the rest back together.

When the sun comes up, all the pirates notice that what's left in the pile is much smaller than the night before. None of them say anything, though, because they're all guilty and don't want the others to decide to eat him instead. They divide up what's left into 5 piles. This time, there's none leftover for the parrot. (Suits it right. The dang thing never even thanked them for the mangoes last night.)

All the pirates munch on their pile while thinking about their secret stash they can sneak back to later. One dies later of an infected cut he received during the battle. The rest are rescued by a passing ship. Three more are killed when the rescue ship is sunk by a storm. The last survives in a dinghy and eventually reaches the mainland. He lives for another 26 years, eventually dying of heart disease. He never found true love or happiness in life. His fondest memory is of eating mangoes on a tropical island with 4 men he had bonded with through the fires of battle.

What is the minimum number of mangoes in the original pile?

Note that mangoes are counted as integers.
There will be no decimal or negative mangoes allowed.

## marked as duplicate by kaine, Engineer Toast, Community♦Apr 29 '15 at 17:38

• That ending is....more depressing than mine was...and mine implied they killed the monkey. – kaine Apr 29 '15 at 17:20
• @kaine You're absolutely right. I searched for monkeys and coconuts but not bananas. I'll vote to close. Yours is better, anyway. – Engineer Toast Apr 29 '15 at 17:23
• To see an explanation, go here – A.D. May 1 '15 at 11:29

The question is best understood with a basic grasp of modular arithmetic. The answer:

3121

Because:

You need to find a number to fit that, mod 5, is 1. Then 4/5ths of that mod 5 is 1. Then 4/5ths - 1 of that etc. Then, 4/5ths of that mod 5 is 0. I brute forced it at this point, with this.

• Didn't you forget to remove the share of each pirate before each new iteration? – A.D. Apr 29 '15 at 17:08
• I'm disappointed in myself for not adding the [no-computers] tag as I originally meant to do. There are some more clever solutions so I won't mark this yet so others will stop by to take a look. You'll get the check mark, though. – Engineer Toast Apr 29 '15 at 17:10
• Here's a most likely not coincidence: $5^5=3125$ – user10203 Apr 29 '15 at 17:15
• @Reticality That hints at the more clever solution, to be sure. You add 4 more mangoes to the pile. Every irate makes 5 piles with 1 extra mango on each other pile. The parrot gets nothing. At the end, take out the 4 extra and divvy up the rest. – Engineer Toast Apr 29 '15 at 17:22

Suppose that $a$ is the what's left in the morning. $a$ must be a multiple of 5, of course, else they could not split it.
To obtain what the fifth pirate had, let's say $b$, we do
$b=\frac54 a +1$

As well, we can do the same for the other pirates:

$c=\frac54 b +1$

$d=\frac54 c +1$

$e=\frac54 d +1$

$f=\frac54 e +1$

Where $f$ is the original amount of mangos. Now, we can chain all those equations to get $f$ in correspondence to $a$. The denominator of that fraction is, of course, $4^5=1024$.
The numerator is
$(((((a\times5 +4)\times5 +16)\times5 +64) \times5 +256)\times5 +1024)$

$((((25a +36)\times5 +64) \times5 +256)\times5 +1024)$

$(((125a +244) \times5 +256)\times5 +1024)$

$((625a +1476)\times5 +1024)$

$(3125a +8404)$

When is $(3125a +8404)\over1024$ integer? That's an easy diophantine equation, which solves for $a=1020$, returning $3121$ mangos!

The answer is $3121$ mangos!

• I won't bother writing a further explanation until you read the duplicate. The answerers there did a very good job. – kaine Apr 29 '15 at 17:25
• @kaine I never read duplicates while I'm solving the problem, because I want to find the answer my way, not see others' one :-) – leoll2 Apr 29 '15 at 17:35
• @EngineerToast This is an answer using math and no-computers, I hope you appreciate it :-) – leoll2 Apr 29 '15 at 17:36
• Fair point. I figured you'd solved it and it might not be worth the effort to put the work into explaining it. – kaine Apr 29 '15 at 17:36