Find squares n where n+1 is prime: Difference between revisions
Find squares n where n+1 is prime (view source)
Revision as of 16:08, 18 December 2021
, 2 years ago→{{header|ALGOL 68}}: Other than 1, only consider even squares, as in other samples
SqrtNegInf (talk | contribs) (→{{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" ) )
▲ FOR i FROM 2 BY 2 TO UPB prime WHILE INT i2 = i * i;
i2 < UPB prime
DO
IF prime[ i2 + 1 ] THEN
|