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

// 参考题解
// https://www.luogu.com.cn/problem/solution/B3925
#include <bits/stdc++.h>
using namespace std;
long long i = 0, k = 1, f = 1, m, n;
int main() {
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; // 此时记得重新开始循环
}
k = k / (n - 1) * n + m; // 上文提及的公式
}
cout << k;
return 0;
}