Hosted by
|
package body Primes is
function Prime
(N : in Positive)
return Boolean
is
D : Positive := 2;
begin
if N = 2 then return True; end if;
loop
if N mod D = 0 then return False; end if;
if N / D < D then return True; end if;
D := D + 1;
end loop;
end Prime;
function Next_Prime
(N : in Positive)
return Positive
is
Result : Positive := N;
begin
if Result mod 2 = 0 then
if Result = 2 then return 2; end if;
Result := Result + 1;
end if;
loop
exit when Prime(Result);
Result := Result + 2;
end loop;
return Result;
end Next_Prime;
end Primes;
|