Anonymous user
Lucas-Lehmer test: Difference between revisions
m
→[[Lucas-Lehmer_test#ALGOL 68]]: fix pre tag
(Completed output) |
m (→[[Lucas-Lehmer_test#ALGOL 68]]: fix pre tag) |
||
Line 67:
=={{header|ALGOL 68}}==
{{works with|
<lang algol68>main:(▼
PRAGMAT stack=1M precision=20000 PRAGMAT▼
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
PROC is prime = ( INT p )BOOL:▼
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of FORMATted transput}}
IF p = 2 THEN TRUE▼
ELIF p <= 1 OR p MOD 2 = 0 THEN FALSE▼
ELSE▼
WHILE prime := p MOD i /= 0 DO SKIP OD;▼
prime▼
FI;▼
ELSE▼
LONG LONG INT m p := LONG LONG 2 ** p - 1, s := 4;▼
BOOL prime
FOR i FROM 3
FROM 3 TO p DO
s := (s ** 2 - 2) MOD m p
FI;
test:(
INT upb prime = ( long long bits width - 1 ) OVER 2; # no unsigned #
INT upb count = 45; # find 45 mprimes if INT has enough bits #
Line 108 ⟶ 112:
)</lang>
Output:
<pre>
M2 M3 M5 M7 M13 M17 M19 M31 M61 M89 M107 M127 M521 M607 M1279 M2203 M2281 M3217 M4253 M4423 M9689 M9941 M11213 M19937 M21701 M23209
</pre>
See also: http://www.xs4all.nl/~jmvdveer/mersenne.a68.html
|