|
- //Flash ActionScript 1.0
- //逆归, 穷举范围1~500
- function getAmount(monkeyCount, lastCount) {
- var eachCount;
- if (monkeyCount == 1) {
- eachCount = lastCount;
- } else {
- eachCount = getAmount(monkeyCount-1, lastCount)/4;
- }
- return eachCount*5+1;
- }
- var tempCount;
- for (i=1; i<=500; i++) {
- tempCount = getAmount(5, i);
- if ((tempCount-Math.floor(tempCount)) != 0) {
- continue;
- } else {
- trace("共有"+tempCount+"只桃子, 最后一只猴子那份有"+i+"只桃子.");
- break;
- }
- }
复制代码
output:
共有3121只桃子, 最后一只猴子那份有255只桃子. |
|