Factors of a Mersenne number: Difference between revisions

m (oct...)
Line 21:
{{trans|Fortran}}
 
{{works with|ALGOL 68|Standard - nowith extensionsprelude toinserted language usedmanually}}
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!-- {{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386}}
Compiles, but I couldn't maxint not in library, works with manually entered maxint, bits width. Leaving some issue with newline -->
<lang algol>PROC is prime = (INT number)BOOL:BEGIN
<pre>
PROC is prime = (INT number)BOOL:BEGIN
SKIP # code omitted - see Primality by Trial Division #
END;
 
MODE POWMODSTRUCT = INT;
PR READ "prelude/pow_mod.a68" PR;
 
PROC m factor = (INT p)INT:BEGIN
Line 46 ⟶ 48:
SKIP
ELSE
n := 1pow mod(2,p,q);
FOR i FROM msb BY -1 TO 0 DO
IF ( BIN p SHR i AND 2r1 ) = 2r1 THEN
n := n*n*2 MOD q
ELSE
n := n*n MOD q
FI
OD;
IF n = 1 THEN
m factor := q;
Line 81 ⟶ 76:
FI
 
END</lang>
</pre>
Example:
<pre>