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.

24 lines
598 B

1 year ago
// 参考题解
// https://www.luogu.com.cn/problem/solution/B3925
1 year ago
#include <bits/stdc++.h>
using namespace std;
1 year ago
long long i = 0, k = 1, f = 1, m, n;
1 year ago
int main() {
1 year ago
cin >> n >> m;
if (n == 1) { // 当n=1时进行特判
cout << "1";
return 0;
}
k = f * n + m;
for (i = 1; i <= n; i++) {
if (k % (n - 1) != 0) {
i = 1;
f++;
k = f * n + m;
continue; // 此时记得重新开始循环
1 year ago
}
1 year ago
k = k / (n - 1) * n + m; // 上文提及的公式
1 year ago
}
1 year ago
cout << k;
1 year ago
return 0;
}