blob: 1a4ac8a5d2b64c5e2ccf35ee86342536c5dd3341 (
plain)
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
|
program Ch2;
{$mode objfpc}
uses
SysUtils, Math, GVector;
type
TVec = specialize TVector<Integer>;
var
I:Integer;
Vec:TVec;
function IsPrime(N:Integer):Boolean;
begin
if N <= 1 then Exit(False);
for I := 2 to Trunc(Sqrt(N)) do
if N mod I = 0 then Exit(False);
Result := True;
end;
function CubanPrimes(N:Integer):TVec;
var
I,P:Integer;
Vec:TVec;
begin
I := 1;
Vec := TVec.Create;
while True do
begin
P := 3 * I * (I + 1) + 1;
if(IsPrime(P)) then Vec.PushBack(P);
if(P >= N) then break;
Inc(I);
end;
Result := Vec;
end;
begin
Vec := CubanPrimes(1000);
for I := 0 to Vec.Size-1 do Write(Vec[I], ' ');
FreeAndNil(Vec);
end.
|