Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <map>
- #include <string>
- #include <cstring>
- #include <cmath>
- #include <set>
- #include <list>
- #include <queue>
- using namespace std;
- #define LL long long
- #define V vector
- #define VI V<int>
- #define VII V<VI>
- #define FOR(t,l,r) for (int t=l; t<r; t++)
- #define FORL(t,l,r) for (LL t=l; t<r; t++)
- const double mth_pi=2*acos(0.);
- #define pi mth_pi
- #define inf (1<<23)
- #define eps 1e-5
- #define pb push_back
- #define mp make_pair
- #define sz size()
- #define mii map<int,int>
- #define pii pair<int,int>
- #define x first
- #define y second
- const int NN=1234567;
- int lp[NN+1], pr[NN], cc=0;
- void resh () {
- FOR(i,2,NN+1) {
- if (!lp[i]) {
- lp[i]=i, pr[cc++]=i;}
- int t=i*pr[0];
- for (int j=0; j<cc && pr[j]<=lp[i] && t<=NN; ++j, t=i*pr[j])
- lp[t]=pr[j];} }
- int main () {
- int a, b, k, kk, t;
- cin >>a>>b>>k;
- VI p; resh();
- for (t=a; t<=b; ++t) if (lp[t]==t) p.pb(t);
- int n=p.sz, l=0;
- if (n<k) {cout <<"-1\n"; return 0;}
- for (t=0; t<n-k; ++t) l=max(l,p[t+k]-p[t]);
- kk=0;
- for (t=a; t<=a+l-1; ++t) kk+=(lp[t]==t);
- while (t<=b && kk<k) kk+=(lp[t]==t), t++, l++;
- if (l>b-a+1) {cout <<"-1\n"; return 0;}
- kk=0;
- for (t=b; t>=b-l+1; --t) kk+=(lp[t]==t);
- while (t>=a && kk<k) kk+=(lp[t]==t), t--, l++;
- if (l>b-a+1) {cout <<"-1\n"; return 0;}
- cout <<l<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement