Lucas-Lehmer test: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: straight from A68 ☺ ... python does rather well with arbitary precision, fast too.) |
m (→{{header|Ada}}: Changed from long_long_integer to 64 bit unsigned integer) |
||
Line 12: | Line 12: | ||
procedure Lucas_Lehmer_Test is |
procedure Lucas_Lehmer_Test is |
||
type Ull is mod 2**64; |
|||
function Mersenne(Item : Integer) return Boolean is |
function Mersenne(Item : Integer) return Boolean is |
||
S : |
S : Ull := 4; |
||
MP : |
MP : Ull := 2**Item - 1; |
||
begin |
begin |
||
if Item = 2 then |
if Item = 2 then |
||
return True; |
return True; |
||
else |
else |
||
for I in 3..Item loop |
|||
S := (S * S - 2) mod MP; |
S := (S * S - 2) mod MP; |
||
end loop; |
end loop; |
||
Line 38: | Line 39: | ||
end loop; |
end loop; |
||
end Lucas_Lehmer_Test; |
end Lucas_Lehmer_Test; |
||
Output: (Output was truncated by an arithmetic overflow exception.) |
|||
Output: |
|||
Mersenne primes: |
Mersenne primes: |
||
M2 M3 M5 M7 M13 M17 M19 M31 |
M2 M3 M5 M7 M13 M17 M19 M31 |