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.
|
|
|
|
#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;
|
|
|
|
|
}
|