桃子的总数是 3121。
用的方法简单粗暴,就是通过反复迭代枚举得来。
下面是我写的代码
#include <stdio.h>
int main(int argc, const char * argv[]) {
// Variable Definition
int peachNum = 1;
int monkeyNum = 1;
int peachNumTemp = peachNum;
// Deal with the process
while (monkeyNum != 6) {
if (peachNumTemp % 5 == 1) {
peachNumTemp = (peachNumTemp - 1) - (peachNumTemp - 1) / 5;
monkeyNum++;
} else {
peachNum++;
peachNumTemp = peachNum;
monkeyNum = 1;
}
}
// Print out the result
printf("Total number of peaches is: %d\n",peachNum);
} |