#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7; constexpr ll MAX = 10000000000LL; constexpr ll SQRT = 100000LL; bool isprime[SQRT + 1]; template constexpr T INF = numeric_limits::max() / 100; int main() { cin.tie(0); ios::sync_with_stdio(false); fill(isprime, isprime + SQRT + 1, true); for (ll i = 2; i <= SQRT; i++) { if (isprime[i]) { for (ll j = 2; i * j <= SQRT; j++) { isprime[i * j] = false; } } } vector prime; for (ll i = 2; i <= SQRT; i++) { if (isprime[i]) { prime.push_back(i); } } isprime[1] = true; ll L, H; cin >> L >> H; if (H - L < 1000) { ll maxi = SQRT; ll maxnum = 0; for (ll i = L; i <= H; i++) { for (const ll p : prime) { if (i % p == 0 and (not(i <= SQRT and isprime[i]))) { if (maxi <= p) { maxi = p; maxnum = i; break; } } } } cout << maxnum << endl; return 0; } reverse(prime.begin(), prime.end()); vector cand(1, 1LL); for (const ll p : prime) { vector tmp = cand; ll maxi = -1; for (const ll e : cand) { ll num = e; while (num * p <= H) { num *= p; if (num >= L and (not(num <= SQRT and isprime[num]))) { maxi = max(maxi, num); } tmp.push_back(num); } } if (maxi != -1) { cout << maxi << endl; return 0; } cand = tmp; } return 0; }