#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INIT std::ios::sync_with_stdio(false);std::cin.tie(0); // VAR(int, x); #define VAR(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__); template void Scan(T& t) { std::cin >> t; } templatevoid Scan(First& first, Rest&...rest) { std::cin >> first; Scan(rest...); } #define OUT(d) std::cout< c(n);for(auto& i:c)std::cin>>i; #define MAT(type, c, m, n) std::vector> c(m, std::vector(n));for(auto& r:c)for(auto& i:r)std::cin>>i; #define ALL(a) (a).begin(),(a).end() #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i=0;--i) #define PAIR std::pair #define IN(a, x, b) (a<=x && x<=b) #define IN2(a0, y, a1, b0, x, b1) (a0<=y && y(end-start).count();std::cerr<<"[Time:"< 0) { res |= 1 << (n % 10); n /= 10; } return res; } // O( nの桁数 ) std::vector GetPrimeVec(int n) { std::vector num(n, true); std::vector prime; num[0] = false; for (int i = 0; i < std::sqrt(n); ++i) { if (num[i]) { for (int j = 2; (i + 1)*j <= n; ++j) { num[(i + 1)*j - 1] = false; } } } for (int i = 0; i < n; ++i) { if (num[i]) { prime.emplace_back(i + 1, bitUsedNum(i + 1)); } } return prime; } // O( sqrt(n) ) signed main() { INIT; VAR(int, n); int ansBit = 0; REP(i, n) { VAR(int, a); ansBit |= 1 << a; } auto prime = GetPrimeVec(5000000); prime.emplace_back(5000001, 1 << 11); int l = 0, r = -1; int max = -1; int checkBit = 0; while (++r < prime.size()) { int t = prime[r].second; int t2 = t | ansBit; if (t2 != ansBit || r + 1 == prime.size()) { if (checkBit == ansBit && l != r) { int K, L; if (l == 0) K = 1; else K = prime[l - 1].first + 1; L = prime[r].first - 1; max = std::max(max, L - K); } checkBit = 0; l = r + 1; } else { checkBit |= t; } } OUT(max)BR; return 0; }