#ifdef LOCAL //#define _GLIBCXX_DEBUG #endif //#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; typedef long long ll; typedef pair P; typedef pair Pi; typedef vector Vec; typedef vector Vi; typedef vector Vs; typedef vector Vc; typedef vector

VP; typedef vector> VV; typedef vector> VVi; typedef vector> VVc; typedef vector>> VVV; typedef vector>>> VVVV; #define endl '\n' #define REP(i, a, b) for(ll i=(a); i<(b); i++) #define PER(i, a, b) for(ll i=(a); i>=(b); i--) #define rep(i, n) REP(i, 0, n) #define per(i, n) PER(i, n, 0) const ll INF=1e18+18; const ll MOD=1000000007; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define YES(n) cout << ((n) ? "YES" : "NO") << endl; #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define pb(x) push_back(x) #define mp(a, b) make_pair(a,b) #define Each(a,b) for(auto &a :b) #define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i) #ifdef LOCAL #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define dbgmap(mp) cerr << #mp << ":"<first <<":"<second << endl;} #define dbgset(st) cerr << #st << ":"<bool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream &operator<<(ostream &s, const pair &p) { return s<<"("<istream& operator>>(istream&i,vector&v) {rep(j,v.size())i>>v[j];return i;} // vector template ostream &operator<<(ostream &s, const vector &v) { int len=v.size(); for(int i=0; i ostream &operator<<(ostream &s, const vector > &vv) { int len=vv.size(); for(int i=0; i divisor(ll n) { vector ret; for(ll i=1; i*i<=n; i++) { if(n%i==0) { ret.pb(i); if(i*i!=n) { ret.pb(n/i); } } } return ret; } vector> factorize(ll n) { vector> res; for (ll i = 2; i*i <= n; ++i) { if (n%i) continue; res.emplace_back(i,0); while (n%i == 0) { n /= i; res.back().second++; } } if (n != 1) res.emplace_back(n,1); return res; } ll POW(ll x, ll p){ ll res = 1; while(p--){ if(__builtin_mul_overflow(res,x, &res)){ return -INF; } } return res; } int solve(){ ll n; cin>>n; ll ans = n-1; //n(p-1) = k(p^x-1) st. k < p if(n==1){ out(2); return 0; } if(n==2){ out(3); return 0; } Vec div = divisor(n); //x = 2 { Each(k, div){ ll p = n/k - 1; if(k 2 { Each(k, div){ REP(x,3,61){ ll L = 2; ll R = 1000004; while(L+1= n/k ){ ok = false; } if(ok){ L = p; }else{ R = p; } } if((POW(R,x)-1) / (R-1) == n/k){ if(k < R){ dbg(mp(mp(R,k),x)) chmin(ans, R); } } } } } out(ans); return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout<>T; // while(T--) solve(); }