Quadrat special primes: Difference between revisions
Content added Content deleted
(clarify task) |
(→{{header|ALGOL 68}}: Use ALGOL 68-primes) |
||
Line 9: | Line 9: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{Trans|ALGOL W}} |
{{Trans|ALGOL W}} |
||
{{libheader|ALGOL 68-primes}} |
|||
<lang algol68>BEGIN # find some primes where the gap between the current prime and the next is a square # |
<lang algol68>BEGIN # find some primes where the gap between the current prime and the next is a square # |
||
# reurns a sieve of primes up to n # |
|||
PROC eratosthenes = ( INT n )[]BOOL: |
|||
BEGIN |
|||
[ 1 : n ]BOOL p; |
|||
p[ 1 ] := FALSE; p[ 2 ] := TRUE; |
|||
FOR i FROM 3 BY 2 TO n DO p[ i ] := TRUE OD; |
|||
FOR i FROM 4 BY 2 TO n DO p[ i ] := FALSE OD; |
|||
FOR i FROM 3 BY 2 TO ENTIER sqrt( n ) DO |
|||
IF p[ i ] THEN FOR s FROM i * i BY i + i TO n DO p[ s ] := FALSE OD FI |
|||
OD; |
|||
p |
|||
END # eratosthenes # ; |
|||
# an array of squares # |
# an array of squares # |
||
PROC get squares = ( INT n )[]INT: |
PROC get squares = ( INT n )[]INT: |
||
Line 30: | Line 19: | ||
END # get squares # ; |
END # get squares # ; |
||
INT max number = 16000; |
INT max number = 16000; |
||
PR read "primes.incl.a68" PR |
|||
[]BOOL prime = |
[]BOOL prime = PRIMESIEVE max number; |
||
[]INT square = get squares( max number ); |
[]INT square = get squares( max number ); |
||
INT p count, this prime, next prime; |
INT p count, this prime, next prime; |