#include #include using namespace std; vector make_primes(int32_t a, int32_t b){ vector ps; if(a <= 2 && 2 <= b) ps.emplace_back(2); if(a <= 3 && 3 <= b) ps.emplace_back(3); a = max(5, a); for(; a <= b; a++){ bool f = true; for(int32_t i = 2; i * i <= a; i++) f &= !!(a % i); if(f) ps.emplace_back(a); } return ps; } int main(){ int32_t k, n; cin >> k >> n; auto hashed = make_primes(k, n), ps = hashed; for(auto& p:hashed) while(10 <= p) p = p / 10 + p % 10; bool used[10]{}; int32_t ans = 0, maxsize = 0, l = 0, r = 0; while(l < hashed.size() && r < hashed.size()){ if(used[hashed[r]]){ while(hashed[l] != hashed[r]) l++; l++; r++; }else used[hashed[r++]] = true; if(maxsize <= r - l && l < hashed.size()){ maxsize = r - l; ans = ps[l]; } } cout << ans << endl; }