3.0 KiB
3.0 KiB
title | id | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
Sailors, coconuts and a monkey problem | 59da22823d04c95919d46269 | 5 | 水手,椰子和猴子问题 |
Description
五名水手在岛上遭遇海难,并在白天收集了一大堆椰子。
那天晚上,第一个水手醒来并决定早点拿走他的第一份,所以试图将一堆椰子平分成五堆,但发现剩下一个椰子,所以他把它扔到一只猴子然后隐藏“他的”五个同样大小的椰子堆中的一个,并将其他四个桩推到一起,再次形成一堆可见的椰子并上床睡觉。
长话短说,每个水手轮流在夜间起床,并执行将椰子堆分成五个的相同动作,发现剩下一个椰子并将剩下的椰子留给猴子。
在早上(在夜间五个水手的暗中和分开行动之后),剩下的椰子被分成五个相等的堆,每个水手,然后发现一堆椰子在水手之间平分没有余数。 (早上猴子没什么。)
任务:
Create a function that returns the the minimum possible size of the initial pile of coconuts collected during the day for N sailors.
注意:
Of course the tale is told in a world where the collection of any amount of coconuts in a day and multiple divisions of the pile, etc can occur in time fitting the story line, so as not to affect the mathematics.
CF卡:
猴子和椰子 - Numberphile (视频)分析解决方案。
<a href="http://oeis.org/A002021" title="link: http://oeis.org/A002021">A002021 Pile of coconuts problem</a> The On-Line Encyclopedia of Integer Sequences. (Although some of its references may use the alternate form of the tale).
Instructions
Tests
tests:
- text: <code>splitCoconuts</code>是一个函数。
testString: 'assert(typeof splitCoconuts === "function", "<code>splitCoconuts</code> is a function.");'
- text: <code>splitCoconuts(5)</code>应该返回3121。
testString: 'assert(splitCoconuts(5) === 3121, "<code>splitCoconuts(5)</code> should return 3121.");'
- text: <code>splitCoconuts(6)</code>应返回233275。
testString: 'assert(splitCoconuts(6) === 233275, "<code>splitCoconuts(6)</code> should return 233275.");'
- text: <code>splitCoconuts(7)</code>应该返回823537。
testString: 'assert(splitCoconuts(7) === 823537, "<code>splitCoconuts(7)</code> should return 823537.");'
Challenge Seed
// noprotect
function splitCoconuts(intSailors) {
// Good luck!
return true;
}
Solution
// solution required