// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using mint = modint998244353; // using mint = modint1000000007; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pll = pair; using T = tuple; using G = vector>; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep2(i, a, b) for (ll i = a; i < (b); ++i) #define rrep2(i, a, b) for (ll i = a-1; i >= (b); --i) #define rep3(i, a, b, c) for (ll i = a; i < (b); i+=c) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second #define UNIQUE(v) sort(rng(v)), v.erase(unique(rng(v)), v.end()) #define MIN(v) *min_element(rng(v)) #define MAX(v) *max_element(rng(v)) template bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,T b){if(a void printv(vector &v){rep(i,v.size())cout< void printvv(vector> &v){rep(i,v.size())rep(j,v[i].size())cout<> k >> n; vector prime; vector used(n+1); for(int i=2; i<=n; i++){ if(used[i]) continue; if (k <= i) prime.emplace_back(i); for(int j=i; j<=n; j+=i) used[j] = true; } auto f = [&](auto f, int d) -> int{ int res = 0; while(d){ res += d%10; d /= 10; } if (res <= 9) return res; else return f(f, res); }; int m = prime.size(); vector h(m); rep(i, m) h[i] = f(f, prime[i]); int max_s = 0, max_p = -1; for(int i = m-1; i >= 0; i--){ set st = {h[i]}; for(int j = 1; j < 9; j++){ if (i+j >= m) break; if (st.count(h[i+j])){ if (max_s < st.size()){ max_s = st.size(); max_p = prime[i]; } break; } st.insert(h[i+j]); } if (max_s < st.size()){ max_s = st.size(); max_p = prime[i]; } } cout << max_p << endl; return 0; }