You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python/GESP/New_WuHouFenTao_1.cpp

22 lines
712 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
// 5只猴子需要多少个桃子3121
//
// 6只猴子
int main() {
for (int i = 6;; i += 5) { // 逐个尝试有i个桃子
int x = i; // 拷贝出来,防止错误的修改
int j;
for (j = 0; j < 5; j++) { // 尝试5个猴子分5回
if ((x - 1) % 5 != 0 || x <= 1) // 扔掉一个是否能分成5份
break; // 不符合要求
x = (x - 1) * 4 / 5; // 分完第j+1次后剩下的桃子
}
if (j == 5) { // 符合条件
printf("%d", i);
exit(0);
}
}
return 0;
}