#include #include #include #include using namespace std; vector getPrimes(int n) { vector ok(n, true); ok[0] = ok[1]= false; vector ret; for (int i = 2; i < n; i++) { if (!ok[i]) continue; ret.push_back(i); for (int j = i; j < n; j += i) ok[j] = false; } return ret; } long long minfac(long long x) { for (long long d = 2; d * d <= x; d++) { if (x % d == 0) return d; } return x; } int main(int argc, char *argv[]) { long long l, h; cin >> l >> h; vector ps = getPrimes(150000); for (int i = ps.size()-1; i >= 0; i--) { long long x = h / ps[i] * ps[i]; long long lb = max(l, ps[i] * ps[i]); while (x >= lb) { long long d = minfac(x / ps[i]); if (d > ps[i]) { cout << x << endl; return 0; } x -= ps[i]; } } throw; }