Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Lucas-Lehmer-test/DWScript/lucas-lehmer-test.dw
Normal file
26
Task/Lucas-Lehmer-test/DWScript/lucas-lehmer-test.dw
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
function IsMersennePrime(p : Integer) : Boolean;
|
||||
var
|
||||
i, s, m_p : Integer;
|
||||
begin
|
||||
if p=2 then
|
||||
Result:=True
|
||||
else begin
|
||||
m_p := (1 shl p)-1;
|
||||
s := 4;
|
||||
for i:=3 to p do
|
||||
s:=(s*s-2) mod m_p;
|
||||
Result:=(s=0);
|
||||
end;
|
||||
end;
|
||||
|
||||
const upperBound = Round(Log2(High(Integer))/2);
|
||||
|
||||
PrintLn('Finding Mersenne primes in M[2..' + IntToStr(upperBound) + ']: ');
|
||||
Print('M2');
|
||||
|
||||
var p : Integer;
|
||||
for p:=3 to upperBound step 2 do begin
|
||||
if IsMersennePrime(p) then
|
||||
Print(' M'+IntToStr(p));
|
||||
end;
|
||||
PrintLn('');
|
||||
Loading…
Add table
Add a link
Reference in a new issue