Delphi checks whether the specified number is a prime number

From , 3 Years ago, written in Delphi (Object Pascal), viewed 108 times.
URL https://pastebin.vip/view/04e299e2
  1. function IsPrime(N: Integer): Boolean;
  2. var
  3.   Max: Integer;     // max divisor
  4.   Divisor: Integer; // different divisors to try
  5. begin
  6.   Result := False;
  7.   if N < 2 then
  8.     Exit; // not a prime
  9.   Result := True;
  10.   if N = 2 then
  11.     Exit; // 2 is prime
  12.   if N mod 2 = 0 then
  13.     Result := False; // even numbers > 2 are not prime
  14.   Max := Trunc(Sqrt(N)) + 1;
  15.   Divisor := 3;
  16.   // test odd numbers
  17.   while (Max > Divisor) and Result do
  18.   begin
  19.     if (N mod Divisor) = 0 then
  20.       Result := False;
  21.     Inc(Divisor, 2); // next odd number
  22.   end;
  23. end;
  24. //delphi/2278

Reply to "Delphi checks whether the specified number is a prime number"

Here you can reply to the paste above

captcha

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