program PrimeFibonacci;
{$mode objfpc}
function IsPrime(n: QWord): Boolean;
var
i: QWord;
begin
if n < 2 then Exit(False);
if (n = 2) or (n = 3) then Exit(True);
if n mod 2 = 0 then Exit(False);
i := 3;
while i * i <= n do
begin
if n mod i = 0 then Exit(False);
Inc(i, 2);
end;
Result := True;
end;
function NextFib(var a, b: QWord): QWord;
var
f, nextVal: QWord;
begin
f := a;
nextVal := a + b;
a := b;
b := nextVal;
NextFib := f;
end;
var
a, b, f: QWord;
count: Integer;
begin
a := 1;
b := 1;
count := 0;
while count < 10 do
begin
f := NextFib(a, b);
if IsPrime(f) then
begin
Write(f, ' ');
Inc(count);
end;
end;
end.
(*
run:
2 3 5 13 89 233 1597 28657 514229 433494437
*)