#include<iostream> #include<cmath> #include<unordered_map> #define ll long long usingnamespacestd;
constint p = 998244353;
ll pow_mod(ll x, ll n){ ll s = 1; for (; n; n >>= 1, x = x * x % p) if (n & 1) s = s * x % p; return s; }
ll n, x;
unordered_map<int, int> mp1, mp2; intbsgs(int p, int a, int b1, int b2){ int q = ceil(sqrt(p)); ll mul = 1; mp1.clear(); mp2.clear(); for (int i = 0; i <= q; ++i) { mp1[mul * b1 % p] = i; mp2[mul * b2 % p] = i; mul = mul * a % p; } mul = 1; ll aq = pow_mod(a, q); for (int i = 1; i <= q; ++i) { mul = mul * aq % p; if (mp1.find(mul) != mp1.end()) return (i * q - mp1[mul]) * 2; if (mp2.find(mul) != mp2.end()) return (i * q - mp2[mul]) * 2 + 1; } return-1; }
voidwork(){ cin >> n >> x; if (x == 1) returncout << 0 << "\n", void(); if (x == 0) returncout << 1 << "\n", void(); x = x * n % p; int ans = bsgs(p, (n - 1) * (n - 1) % p, (x - n + 1 + p) % p, (x + n - 1) * pow_mod(n - 1, p - 2) % p), Ans = p + 1; if (~ans) cout << ans << "\n"; elsecout << -1 << "\n"; }