{
  Copyright (C) 2020 I. Kakoulidis, <ioulianos.kakoulidis@hotmail.com>
  https://g...content-available-to-author-only...b.com/JulStrat/primesieve-pas

  This file is distributed under the BSD 2-Clause License.
}

program hprimes;
{$IF Defined(FPC)}{$MODE Delphi}{$ASMMODE Intel}{$ENDIF}

function MulModASM(a, b: UInt64; m: UInt64): UInt64;
label
  MUL_MOD;

asm
  MOV RCX, m
  MOV RAX, a
  CMP RAX, RCX
  JB MUL_MOD
  XOR RDX, RDX
  DIV RCX
  MOV RAX, RDX

MUL_MOD:
  MUL b
  DIV RCX
  MOV @Result, RDX
end;

function PowMod(b, e: UInt64; m: UInt64): UInt64;
begin
  if b >= m then b := b mod m;
  Result := 1;

  while e <> 0 do
  begin
    if (e and 1) = 1 then Result := MulModASM(Result, b, m);
    e := e shr 1;
    b := MulModASM(b, b, m);
  end;
end;

function MillerRabin(n: UInt64): boolean;
var
  a, d, x: UInt64;
  i, r: integer;
  witness: boolean;

begin
  case n of
    2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37: Exit(True);
  end;
  if ((n and 1) = 0) or (n = 1) then Exit(False);
  d := n - 1;
  r := 0;

  while (d and 1) = 0 do
  begin
    Inc(r);
    d := d shr 1;
  end;

  for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] do
  begin
    x := PowMod(a, d, n);
    if (x = 1) or (x = n - 1) then continue;
    witness := false;

    for i := 1 to r - 1 do
    begin
      x := MulModASM(x, x, n);
      if x = n - 1 then
      begin
        witness := true;
        break;
      end;
    end;

    if witness = false then Exit(false);
  end;
  Result := true;
end;

var
  m: UInt64;
  c: integer;

begin
  m := $FFFFFFFFFFFFFFFF;
  c := 0;

  while c < 10 do
  begin
    if MillerRabin(m) then
    begin
      WriteLn(($FFFFFFFFFFFFFFFF - m) + 1);
      Inc(c);
    end;
    m := m - 1;
  end;

end.