#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ int b, c; cin >> b >> c; if (b == 1 && c == 1){ cout << 1 << '\n'; return 0; } auto henkan = [&](const array &ta) -> ll { return (ll)ta[0] | ((ll)ta[1]<<10) | ((ll)ta[2]<<20) | ((ll)ta[3]<<30); }; unordered_map var; vector> dat; rep(i,1,b){ if (__gcd(i,b)==1){ rep(j,0,b){ if(j%c==0){ dat.push_back({i,j,0,1}); var[henkan(dat.back())]=dat.size()-1; } } } } vector inv(b); rep(i,1,b){ if (__gcd(i,b)==1){ rep(j,0,b){ if(i*j%b==1){ inv[i]=j; } } } } int m = dat.size(); vector> datinv; for (auto i: dat){ int x = inv[(i[0]*i[3]%b-i[1]*i[2]%b+b)%b]; datinv.push_back({i[3]*x%b, ((-i[1])%b+b)%b*x%b, ((-i[2])%b+b)%b*x%b, i[0]*x%b}); } auto prod = [&](const array &x, const array &y) -> array { array z={0,0,0,0}; rep(i,0,2){ rep(j,0,2){ rep(k,0,2){ z[i*2+j]+=x[i*2+k]*y[k*2+j]; z[i*2+j]%=b; } } } return z; }; vector seen(m); int cnt = 0; rep(i,0,m){ if (cnt >= 101){ break; } if (seen[i]){ continue; } cnt++; array mat = dat[i]; rep(j,0,m){ seen[var[henkan(prod(prod(dat[j],mat),datinv[j]))]]=1; } } if (cnt>=101){ cout<<"100+"<<'\n'; }else{ cout<