-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
60 lines (57 loc) · 1.04 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[1000005];
vector<long long> primes;
void sieve()
{
for(long long i=2;i*i<=1000000;i++)
{
if(ara[i]==0)
{
for(long long j=i*i;j<=1000000;j+=i)
ara[j]=1;
}
}
}
int main()
{
fastio;
long long a,b,k,i,mx=INT_MIN,l,r;
cin>>a>>b>>k;
sieve();
for(i=a;i<=b;i++)
{
if(i==1)
continue;
if(ara[i]==0)
primes.push_back(i);
}
if(primes.size()<k)
{
cout<<-1<<"\n";
return 0;
}
for(i=a;i<=b;i++)
{
if(i==a)
{
l=0;
r=k-1;
mx=primes[r]-i+1;
}
else if(i>primes[l])
{
l++;
r++;
if(r==primes.size())
{
mx=max(mx,b-primes[l-1]+1);
break;
}
mx=max(mx,primes[r]-i+1);
}
}
cout<<mx<<"\n";
return 0;
}