#include #include #include #include #include #include using namespace std; const int H_MAX_RT = 1e5; vector primes; void make_primes() { vector is_prime(H_MAX_RT + 100, true); is_prime[0] = is_prime[1] = false; int n = is_prime.size(); for (int i = 2; i < n; i++) { if (is_prime[i]) { for (int j = i * 2; j < n; j += i) { is_prime[j] = false; } } } for (int i = 0; i < n; i++) { if (is_prime[i]) { primes.emplace_back(i); } } } int main() { make_primes(); long long l, h; cin >> l >> h; long long diff = h - l + 1; if (diff == 2) { cout << (l % 2 == 0 ? l : h) << endl; return 0; } auto it = upper_bound(primes.begin(), primes.end(), diff); int idx = it - primes.begin(); do { idx--; } while (primes[idx] * primes[idx] > h); do { for (long long i = h; i >= l; i--) { if (i % primes[idx] == 0) { long long tmp = i / primes[idx]; if (tmp == 1) { continue; } bool is_ok = true; for (int i = 0; i < idx; i++) { if (tmp % primes[i] == 0) { is_ok = false; } } if (is_ok) { cout << i << endl; return 0; } } } idx--; } while (idx > 0); return 0; }