Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <string>
- #include <cstring>
- #include <map>
- #include <set>
- #include <vector>
- #include <cmath>
- using namespace std;
- #define f first
- #define s second
- #define sz size()
- const int MAXN = 100 * 100 * 100 + 1;
- const double EPS = 0.000000000001;
- const int INF = 2 * 1000 * 1000 * 1000;
- const int mod = 1000 * 1000 * 1000 + 7;
- int a, b, k, v, t = 0, l, r, m, cnt[MAXN];
- bool used[MAXN];
- bool check (int p) {
- for (int i = a; i <= b - p + 1; i++) {
- if (cnt[i + p - 1] - cnt[i - 1] < k)
- return false;
- }
- return true;
- }
- int main() {
- cin >> a >> b >> k;
- used[0] = used[1] = true;
- for (int i = 2; i < 1001; i++) {
- if (!used[i])
- for (int j = i * i; j <= b; j += i)
- used[j] = true;
- }
- for (int i = 0; i <= b; i++)
- if (!used[i])
- cnt[i] = cnt[i - 1] + 1;
- else
- cnt[i] = cnt[i - 1];
- l = 1;
- r = b - a + 1;
- while (t < 22 && l != r) {
- t++;
- m = (l + r) / 2;
- if (check(m))
- r = m;
- else
- l = m + 1;
- }
- if (check(l)) {
- cout << l;
- return 0;
- }
- if (check(r))
- cout << r;
- else
- cout << -1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement