#include "bits/stdc++.h" using namespace std; using ll=long long; using vll=vector< ll>; using vvll=vector< vll>; using vvvll=vector< vvll>; using vvvvll=vector; using dd=double; using vdd=vector< dd>; using vvdd=vector< vdd>; using pll=pair; using tll=tuple; using qll=tuple; constexpr ll INF = 1LL << 60; struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<::max_digits10); } } fast; #define REPS(i, S, E) for (ll i = (S); i <= (E); i++) #define REP(i, N) REPS(i, 0, (N)-1) #define DEPS(i, S, E) for (ll i = (E); i >= (S); i--) #define DEP(i, N) DEPS(i, 0, (N)-1) #define rep(i, S, E) for (ll i = (S); i <= (E); i++) #define dep(i, E, S) for (ll i = (E); i >= (S); i--) #define each(e, v) for (auto&& e : v) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; } template inline T MaxE(vector&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; } template inline T MinE(vector&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; } template inline T MaxE(vector &v) { return MaxE(v,0,(ll)v.size()-1); } template inline T MinE(vector &v) { return MinE(v,0,(ll)v.size()-1); } template inline T Sum(vector &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; } template inline T Sum(vector &v) { return Sum(v,0,v.size()-1); } template inline ll sz(T &v){ return (ll)v.size(); } inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } //vector用テンプレート template inline vector& operator+=(vector &a,const vector &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]+=b[i]; return a; } template inline vector& operator-=(vector &a,const vector &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]-=b[i]; return a; } template inline vector& operator*=(vector &a,const vector &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]*=b[i]; return a; } template inline vector& operator/=(vector &a,const vector &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]/=b[i]; return a; } template inline vector& operator%=(vector &a,const vector &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]%=b[i]; return a; } template inline vector& operator+=(vector &a,S b){ for (T &e: a) e+=b; return a; } template inline vector& operator-=(vector &a,S b){ for (T &e: a) e-=b; return a; } template inline vector& operator*=(vector &a,S b){ for (T &e: a) e*=b; return a; } template inline vector& operator/=(vector &a,S b){ for (T &e: a) e/=b; return a; } template inline vector& operator%=(vector &a,S b){ for (T &e: a) e%=b; return a; } template inline vector operator+(const vector &a,S b){ vector c=a; return c+=b; } template inline vector operator-(const vector &a,S b){ vector c=a; return c-=b; } template inline vector operator*(const vector &a,S b){ vector c=a; return c*=b; } template inline vector operator/(const vector &a,S b){ vector c=a; return c/=b; } template inline vector operator%(const vector &a,S b){ vector c=a; return c%=b; } template inline vector operator-(S b,const vector &a){ vector c=-a; return c+=b; } template inline vector operator-(const vector &a){ vector c=a; return c*=(-1); } template inline ostream &operator<<(ostream &os,const vector &a){ for (ll i=0; i<(ll)a.size(); i++) os<<(i>0?" ":"")< using namespace atcoder; #endif //// a^b //long long modpow(long long a, long long n, long long mod) { // long long res = 1; // while (n > 0) { // if (n & 1) res = res * a % mod; // a = a * a % mod; // n >>= 1; // } // return res; //} // //// a^-1 //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; //} // //long long modlog(long long a, long long b, ll m) { // a %= m, b %= m; // // // calc sqrt{M} // long long lo = -1, hi = m; // while (hi - lo > 1) { // long long mid = (lo + hi) / 2; // if (mid * mid >= m) hi = mid; // else lo = mid; // } // long long sqrtM = hi; // // // {a^0, a^1, a^2, ..., a^sqrt(m)} // map apow; // long long amari = 1; // for (long long r = 0; r < sqrtM; ++r) { // if (!apow.count(amari)) apow[amari] = r; // (amari *= a) %= m; // } // // // check each A^p // long long A = modpow(modinv(a, m), sqrtM, m); // amari = b; // for (long long q = 0; q < sqrtM; ++q) { // if (apow.count(amari)) { // long long res = q * sqrtM + apow[amari]; // if (res > 0) return res; // } // (amari *= A) %= m; // } // // // no solutions // return -1; //} ll MOD=1; ll modlog(ll x, ll y) { ll H = sqrt(MOD) + 1; static std::pair baby[100010]; for (ll b = 0, xby = y; b < H; b++, xby = (xby * x) % MOD) { baby[b] = std::make_pair(xby, b); } std::sort(baby, baby + H); ll xH = 1; for (int i = 0; i < H; ++i) { xH = (xH * x) % MOD; } for (ll a = 1, xaH = xH; a <= H; a++, xaH = (xaH * xH) % MOD) { auto it = std::lower_bound(baby, baby + H, std::make_pair(xaH + 1, 0LL)); if (it == baby) continue; it--; if (it->first == xaH) return a * H - it->second; } return -1; } void solve() { ll n; cin >> n; if (n==1){ cout << 1 << '\n';return; } MOD=2*n-1; ll x=modlog(2,1); //ll a=2; //ll x=modlog(a,1,m); cout << x << '\n'; } int main(){ #if 0 solve(); #else ll t; cin >> t; rep(i, 0, t-1){ solve(); } #endif return 0; }