#include #include #include using namespace std; const int MAX = 5000000; vector ps; void sieve(){ vector isp(MAX + 10, true); isp[0] = isp[1] = false; for(int p=2;p*p<=MAX;p++)if(isp[p]){ for(int kp=p*p;kp<=MAX;kp+=p)isp[kp] = false; } for(int p=2;p<=MAX;p++)if(isp[p])ps.push_back(p); } int get_len(int s, int t){ if(s > t)return -1; if(s == 0){ s = 1; } else { s = ps[s-1] + 1; } if(t == ps.size() - 1){ t = MAX; } else { t = ps[t+1] - 1; } return t - s; } int solve(int used){ vector mask(ps.size(), 0); for(int i=0;i 0){ int d = p % 10; mask[i] |= 1 << d; p /= 10; } } int res = -1; int start = 0; int acc = 0; for(int i=0;i> N; int used = 0; for(int i=0;i> d; used |= 1 << d; } cout << solve(used) << endl; return 0; }