-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10140.cpp
More file actions
executable file
·55 lines (54 loc) · 1.18 KB
/
10140.cpp
File metadata and controls
executable file
·55 lines (54 loc) · 1.18 KB
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
#include <bits/stdc++.h>
using namespace std;
int const N=INT_MAX;
bool prime[N];
void fun()
{
memset(prime,true,sizeof(prime));
prime[0]=false;
prime[1]=false;
for(int i=2; i*i<=N; i++)
{
if(prime[i])
{
for(int j=i*i; j<=N; j+=i)prime[j]=false;
}
}
}
int main()
{
fun();
int l,r;
while(cin>>l)
{
cin>>r;
int cl,ch,dl,dh;
int maxx=-1,minn=N;
int temp=-1;
cout<<l<<r<<endl;
for(int i=l; i<=r; i++)
{
if(prime[i])
{
temp=i;
if(temp!=-1)
{
if(i-temp<minn)
{
minn=i-temp;
cl=temp;
ch=i;
}
else if(i-temp>maxx)
{
maxx=i-temp;
dl=temp;
dh=i;
}
}
}
}
if(maxx==-1)cout<<"There are no adjacent primes.\n";
else printf("%d,%d are closest, %d,%d are most distant.\n",cl,ch,dl,dh);
}
}