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;
p2 :=
while
if oddOnlyPrimalityTest( p2 - 1 ) then writeon( i_w := 1, s_w := 0, " ", n );▼
n := n + 2;
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 );
|