/* -*- coding: utf-8 -*- * * 1312.cc: No.1312 Snake Eyes - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ /* main */ int main() { ll n; scanf("%lld", &n); // k >= 3 ll s; for (int p = 2; (s = 1 + p + (ll)p * p) <= n; p++) { while (s <= n) { if (n % s == 0 && n / s < p) { printf("%d\n", p); return 0; } s = s * p + 1; } } // k == 2 or k == 1 ll minp = LINF; for (int d = 1; (ll)d * d <= n; d++) if (n % d == 0) { ll m = n / d; ll p2 = m - 1; if (p2 > d && minp > p2) minp = p2; ll p1 = m; if (p1 > d && minp > p1) minp = p1; } printf("%lld\n", minp); return 0; }