#define _USE_MATH_DEFINES #include using namespace std; int cnt1(int x) { int res = 0; for (int i = 2; i * i <= x; i++) { while (x % i == 0) { res++; x /= i; } } return res + (x > 1); } int cnt2(int x) { vector res; for (int i = 2; i * i <= x; i++) { int cnt = 0; while (x % i == 0) { cnt++; x /= i; } if (cnt) res.push_back(cnt); } if (x > 1) res.push_back(1); int ret = 1; for (int i : res) { ret *= (i + 1); } return ret; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int cnt = 0; int ans = 0; for (int x = n - 1; x >= 1; x--) { if (cnt1(__gcd(x, n)) >= k) { int tmp = cnt2(x); if (tmp >= cnt) { cnt = tmp; ans = x; } } } cout << ans << endl; return 0; }