Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main () {
- const int MAX = 20000000;
- vector <bool> S (MAX, true);
- for (int k = 2; k * k <= MAX; k++) {
- if (S[k]) {
- for (int l = k * k; l < MAX; l += k) S[l] = false;
- }
- }
- int M, N;
- cin >> M >> N;
- int count = 0;
- for (int i = 1; i <= N; ++i) {
- count += S[i];
- }
- if (count == M) {
- cout << "1";
- return 0;
- }
- for (int i = N + 1; i < MAX; ++i) {
- count += (S[i] - S[i - N]);
- if (count == M) {
- cout << i - N + 1;
- return 0;
- }
- }
- cout << "-1";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment