#include using namespace std; #define rep(i,n) for (int i = 0; i < (int)(n); ++i) #define rrep(i,n) for (int i = (int)(n-1); i >= 0; --i) #define Rep(i,a,b) for (int i = a; i < b; ++i) #define rRep(i,a,b) for (int i = a; i > b; --i) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define Bit(x,i) (((x)>>(i))&1) using ll = long long; using vi = vector; using vll = vector; using vvi = vector; using vvll = vector; using vb = vector; using vs = vector; using pii = pair; using pll = pair; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N; if(N <= 2) { cout << N+1 << endl; return 0; } Rep(b, 2, 1000002) { ll base = b; while(base < N) base *= b; base--; base /= b-1; if(N%base == 0) { cout << b << endl; return 0; } } ll ans = N+1; for(ll i = 2; i*i <= N; ++i) { if(N%i == 0) { chmin(ans, max(i, N/i)-1); } } cout << ans << endl; }