Pascal classic algorithm - judge whether the number within the Longint range is a prime number

From , 3 Years ago, written in Delphi (Object Pascal), viewed 92 times.
URL https://pastebin.vip/view/c9dd73f5
  1. procedure getprime;
  2. var
  3.   i, j: Longint;
  4.   p: array[1..50000] of Boolean;
  5. begin
  6.   FillChar(p, SizeOf(p), true);
  7.   p[1] := false;
  8.   i := 2;
  9.   while i < 50000 do
  10.   begin
  11.     if p[i] then
  12.     begin
  13.       j := i * 2;
  14.       while j < 50000 do
  15.       begin
  16.         p[j] := false;
  17.         Inc(j, i);
  18.       end;
  19.     end;
  20.     Inc(i);
  21.   end;
  22.   l := 0;
  23.   for i := 1 to 50000 do
  24.     if p[i] then
  25.     begin
  26.       Inc(l);
  27.       pr[l] := i;
  28.     end;
  29. end;
  30.  
  31. function prime(x: Longint): Integer;
  32. var
  33.   i: Integer;
  34. begin
  35.   prime := false;
  36.   for i := 1 to l do
  37.     if pr[i] >= x then
  38.       Break
  39.   else if x mod pr[i] = 0 then
  40.     Exit;
  41.   prime := true;
  42. end;
  43. //delphi/6603

Reply to "Pascal classic algorithm - judge whether the number within the Longint range is a prime number"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website