#include typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; std::set sieve(int n) { std::vector is_prime(n+1); fill(is_prime.begin(), is_prime.end(), true); is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; ++i) { if ( is_prime[i] ) { for (int j = 2*i; j <= n; j += i) is_prime[j] = false; } } std::set ans; for (int i = 0; i < is_prime.size(); ++i) { if ( is_prime[i] ) ans.insert(i); } return ans; } class UselessHash { public: static int hash(int n) { int a = n/10; int b = n%10; if (a == 0) return b; return hash(b+hash(a)); } void solve(void) { int K, N; cin>>K>>N; auto P = sieve(N); if (K > 1) { auto Q = sieve(K-1); for (auto q : Q) P.erase(q); } vector primes(RANGE(P)); vector val(primes); // hash 値に変換 transform(RANGE(val), val.begin(), hash); int ans = 0; int idx = 0; int start = 0; map cnt; // 0 初期化 REP(i, val.size()) cnt.insert(make_pair(val[i], 0)); // しゃくとり法 // O(2*log(n)*n) REP(i, val.size()) { if (cnt[val[i]]) { while (start < val.size() && cnt[val[i]]) { --cnt[val[start]]; ++start; } } ++cnt[val[i]]; int newlen = (i-start+1); if (ans <= newlen) { ans = newlen; idx = start; } } cout<solve(); delete obj; return 0; } #endif