#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N; cin >> N; ll ans = N - 1; // 1 <= d < p // dddddd = d(111111) = d(1+p+p^2+p^3+p^4+p^5) // N = d * (p^(keta) - 1) / (p - 1) vector div; for(ll i = 1; i * i <= N; i++) { if(N % i == 0) { div.push_back(i); if(i * i != N) div.push_back(N / i); } } for(ll d : div) { ll k = N / d; // (p^x - 1) / (p - 1) = N / d = k // p^x - 1 = kp - k // p(k - p^(x-1)) = k - 1 for(ll p = 2; p * p <= k - 1; p++) { if((k - 1) % p == 0) { // k - p^(x-1) = (k - 1) / p = y ll y = (k - 1) / p; // p^(x-1) = k - y = z ll z = k - y; while(z % p == 0) z /= p; if(z == 1) { ans = min(ans, p); } } } } cout << ans << endl; }