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
|
Program A2_18;
Var
n,i:integer;
Function checkprost(n:integer):integer;
Var k,p: integer;
begin
if (n mod
3=0) then checkprost:=0
else
begin
p:=2;
k:=5;
while(k*k<=n) and (n mod k<>0) do
begin
k:=k+p; p:=6-p; end;
if
(k*k>n) then checkprost:=1
else checkprost:=0;
end
end;
begin
readln(n);
i:=5;
while
(i<n) do
begin
if
(checkprost(i)=1) and (checkprost(i+2)=1) then write('(',i,',',i+2,') ');
i:=i+6;
end;
writeln;
readln;
end.
|
// Program A2.18;
#include <iostream>
int checkprost(int n)
{ int k=5,p=2;
if(n%3==0)return 0;
while(k*k<=n && n%k!=0){k=k+p; p=6-p;}
if(k*k>n)
return 1;
else return 0;
}
using namespace std;
int main()
{ int n;
cin>>n;
for (int i=5;i<n;i+=6)
if (checkprost(i)
&& checkprost(i+2)) cout<<"("<<i<<","<<i+2<<")
";
cout<<endl;
return 0;
}
|