#include #include #include using namespace std; vector make_primes(int32_t a, int32_t b){ vector ps; bool e[b + 1]; fill(e, e + b + 1, true); for(int32_t i = 2; i <= b; i++) if(e[i]){ if(a <= i) ps.emplace_back(i); for(int32_t j = 2 * i; j <= b; j += i) e[j] = false; } return ps; } int main(){ int32_t a, b; cin >> a >> b; vector ps = make_primes(a, b), hashed = ps; for(auto& p:hashed) while(10 <= p) p = p / 10 + p % 10; int32_t ans, maxi = 0, lastp[10]{}; for(int32_t i = 0, lpmax = 0; i < hashed.size(); i++){ lpmax = max(lpmax, lastp[hashed[i]]); int32_t dist = i - lpmax + 1; if(maxi <= dist){ maxi = dist; ans = ps[lpmax + 1]; } lastp[hashed[i]] = i; } cout << ans << endl; }