Files
python/GESP/资料/New_WuHouFenTao_3.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

26 lines
930 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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