Jump to content

Mersenne primes: Difference between revisions

→‎{{header|ALGOL W}}: Simplify and avoid overflow
(→‎{{header|ALGOL W}}: Can check 2^31 - 1 without overflow)
(→‎{{header|ALGOL W}}: Simplify and avoid overflow)
Line 68:
for i := 3 step 2 until entier( sqrt( n ) ) do begin;
isPrime := n rem i not = 0;
 
if not isPrime then goto endPrimalityTest
end for_i;
Line 74 ⟶ 75:
 
integer p2, n;
n := 1;
n := 2; % 2^2 is a special case %
p2 := 42;
while
if oddOnlyPrimalityTest( p2 - 1 ) then writeon( i_w := 1, s_w := 0, " ", n );
n := n + 1;begin
p2 := p2 * 2; if n < 3 then begin
while n <= 29 do begin n := n + % odd powers of two up to 29 %1;
if oddOnlyPrimalityTest( p2 - 1 ) then writeon( i_wp2 := 1, s_w := 0, " ",p2 n* );2
n := n + 2; end
if n <= 31 thenelse p2 := p2 * 4begin
n := n + 2;
end while_n_le_31 ;
p2 := p2 * 4
end if_n_le_3__ ;;
if oddOnlyPrimalityTest( p2 - 1 ) then writeon( i_w := 1, s_w := 0, " ", n );
n < 29
end
do begin end ;
% MAXINTEGER is 2**31 - 1 %
if oddOnlyPrimalityTest( MAXINTEGER ) then writeon( i_w := 1, s_w := 0, " ", 31 );
3,048

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.