#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool prime[200001]; int app[10]; long int K, N; vector nums; int main() { long int i, j; int len = 0; int maxlen = 0; int prevlen = 0; int ret; cin >> K; cin >> N; for (i = 2; i <= N; i++) prime[i] = true; for (i = 2; i <= N; i++) { if (prime[i]) { for (j = 2*i; j <= N; j += i) { prime[j] = false; } } } for (i = N; i >= K; i--) { if (prime[i]) { int ci = i; while (ci >= 10) { int sum = 0; for (j = 5; j >= 0; j--) { int temp = floor(ci/pow(10,j)); sum += temp; ci -= temp * pow(10,j); } ci = sum; } for (j = 0; j < 10; j++) { app[j]++; if (j == ci) { len = app[j]; app[j] = 0; } } if (len > prevlen + 1) len = prevlen + 1; if (maxlen < len) { maxlen = len; ret = i; } prevlen = len; } } cout << ret << endl; return 0; }