Find squares n where n+1 is prime: Difference between revisions

→‎{{header|ALGOL 68}}: Other than 1, only consider even squares, as in other samples
(→‎{{header|Perl}}: alternate solutions)
(→‎{{header|ALGOL 68}}: Other than 1, only consider even squares, as in other samples)
Line 10:
[]BOOL prime = PRIMESIEVE 1 000; # construct a sieve of primes up to 1000 #
# find the squares 1 less than a prime (ignoring squares of non-integers) #
# other than 1, the numbers must be even #
FOR i TO UPB prime WHILE INT i2 = i * i;
IF prime[ 2 # i.e.: ( 1 * 1 ) + 1 # ] THEN print( ( " 1" ) ) i2 < UPB primeFI;
FOR i FROM 2 BY 2 TO UPB prime WHILE INT i2 = i * i;
i2 < UPB prime
DO
IF prime[ i2 + 1 ] THEN
3,038

edits