Twin primes: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: Obvious optimisation and remove unnecessary comments) |
(→{{header|ALGOL 68}}: Revised task requirements - check for primes less than the specified number) |
||
Line 61: | Line 61: | ||
# note 2 cannot be one of the primes in a twin prime pair, so we start at 3 # |
# note 2 cannot be one of the primes in a twin prime pair, so we start at 3 # |
||
INT twin count := 0; |
INT twin count := 0; |
||
FOR p FROM 3 BY 2 TO max number DO IF primes[ p ] AND primes[ p - 2 ] THEN twin count +:= 1 FI OD; |
FOR p FROM 3 BY 2 TO max number - 1 DO IF primes[ p ] AND primes[ p - 2 ] THEN twin count +:= 1 FI OD; |
||
print( ( "twin prime pairs below ", whole( max number, 0 ), ": ", whole( twin count, 0 ), newline ) ) |
print( ( "twin prime pairs below ", whole( max number, 0 ), ": ", whole( twin count, 0 ), newline ) ) |
||
END</lang> |
END</lang> |