B3925 [GSEP202312 三级] 小猫分鱼 tj
_colin1112_ · · 题解
与 std 对拍了 1000 组没挂,应该没问题。
思路
枚举第
Code
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
const int E = 1e6 + 5;
ll n, i;
int main()
{
cin >> n >> i;
ll ans;
auto check = [&](ll x) -> bool//lambda表达式
{
ans = x * n + i;//第 n 条鱼
for (int j = 1; j < n; j++)
{
if (ans % (n - 1) != 0)//除不尽
return false;
ans = ans / (n - 1) * n + i;//反之继续逆推
}
return true;
};
ll j = 1;
while (1)
{
if (check(j))
break;
j++;
}
cout << ans;
return 0;
}