#include using namespace std; int cnt[100010]; bool jg[100010]; vector p; void judge_search(long long cur, long long curi, long long c, vector> &v, long long k) { jg[cur] = (c >= k); if (curi == v.size()) return; for (int i = 0; i <= v[curi].second; i++) { judge_search(cur, curi+1, c+i, v, k); cur *= v[curi].first; } } void judge(long long n, long long k) { map m; for (long long i = 2; i * i <= n; i++) { while (n % i == 0) { m[i]++; n /= i; } } if (n != 1) m[n]++; vector> v; for (auto it: m) { v.emplace_back(it); } judge_search(1, 0, 0, v, k); } void search(long long cur, long long curi, long long num) { cnt[cur] = num; if (curi == p.size()) return; if (p[curi] * cur > 100000) return; long long next = cur; long long u = 0; while (next <= 100000) { search(next, curi+1, num*(u+1)); next *= p[curi]; u++; } } vector Eratosthenes(int n){ vector prime(n+1, true); if(n >= 0) prime[0] = false; if(n >= 1) prime[1] = false; for(int i = 2; i * i <= n; i++){ if(prime[i]){ for(int j = i + i; j <= n; j += i) prime[j] = false; } } return prime; } long long gcd(long long a, long long b) { if (a % b == 0) return b; else return gcd(b, a % b); } int main() { auto b = Eratosthenes(100000); for (int i = 0; i <= b.size(); i++) if (b[i]) p.emplace_back(i); search(1, 0, 1); long long n, k; cin >> n >> k; judge(n, k); long long best = 0; long long ans = 0; for (long long i = 1; i < n; i++) { if (jg[gcd(i, n)] && best < cnt[i]) { best = cnt[i]; ans = i; } } cout << ans << endl; return 0; }