#include #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i prime(ll n) { ll m = n; map mp; for(ll i=2;i*i<=n;i++) { while(m % i == 0) { m /= i; mp[i]++; } } if(m > 1) mp[m]++; return mp; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } void solve() { ll n, m; cin >> n >> m; if(n >= m || m == 1) { cout << 0 << endl; return; } if(n == 0) { cout << 1 << endl; return; } int cnt = 0; map mp = prime(m); { bool ok = true; for(auto [x, y] : mp) { cnt += y; ll e = n; rep(i, y) { if(e < x) ok = false; e /= x; } } if(ok) { cout << 0 << endl; return; } } ll ans = 1; if(cnt == 1) { ans = -1; for(ll i=n+1;i> t; while(t--) solve(); return 0; }