Primes whose first and last number is 3: Difference between revisions

Added Algol 68
(Added Algol W)
(Added Algol 68)
Line 10:
Find and show only the   ''number''   of these types of primes   that are   '''<   1,000,000'''.
<br><br>
 
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}} As with the Go and other samples, generates the candidate sequence.
<lang algol68>BEGIN # find some primes whose first and last digits are 3 #
INT max prime = 4000; # largest number to consider #
# sieve the primes to max prime #
[ 1 : max prime ]BOOL prime;
prime[ 1 ] := FALSE; prime[ 2 ] := TRUE;
FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE OD;
FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD;
FOR i FROM 3 BY 2 TO ENTIER sqrt( max prime ) DO
IF prime[ i ] THEN FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD FI
OD;
INT p3count := 0;
# prints n, if it is prime, handles newlines #
PROC p = ( INT n )VOID:
IF prime[ n ] THEN
print( ( " ", whole( n, - 4 ) ) );
IF ( p3count +:= 1 ) MOD 12 = 0 THEN print( ( newline ) ) FI
FI # p #;
# find 1, 2 and 3 digit 3x3 primes #
p( 3 ); p( 33 ); FOR i FROM 0 BY 10 TO 90 DO p( 303 + i ) OD;
# 4 digit 3x3 primes #
FOR i FROM 0 BY 10 TO 990 DO p( 3003 + i ) OD
END</lang>
{{out}}
<pre>
3 313 353 373 383 3023 3083 3163 3203 3253 3313 3323
3343 3373 3413 3433 3463 3533 3583 3593 3613 3623 3643 3673
3733 3793 3803 3823 3833 3853 3863 3923 3943
</pre>
 
=={{header|ALGOL W}}==
3,038

edits