Attractive numbers: Difference between revisions

Added Algol 68
(Add PL/M)
(Added Algol 68)
Line 248:
69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99
102 105 106 108 110 111 112 114 115 116 117 118 119 120</pre>
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find some attractive numbers - numbers whose prime factor counts are #
# prime, n must be > 1 #
PR read "primes.incl.a68" PR
# find the attractive numbers #
INT max number = 120;
[]BOOL sieve = PRIMESIEVE ENTIER sqrt( max number );
print( ( "The attractve numbers up to ", whole( max number, 0 ), newline ) );
INT a count := 0;
FOR i FROM 2 TO max number DO
IF INT v := i;
INT f count := 0;
WHILE NOT ODD v DO
f count +:= 1;
v OVERAB 2
OD;
FOR j FROM 3 BY 2 TO max number WHILE v > 1 DO
WHILE v > 1 AND v MOD j = 0 DO
f count +:= 1;
v OVERAB j
OD
OD;
f count > 0
THEN
IF sieve[ f count ] THEN
print( ( " ", whole( i, -3 ) ) );
IF ( a count +:= 1 ) MOD 20 = 0 THEN print( ( newline ) ) FI
FI
FI
OD;
print( ( newline, "Found ", whole( a count, 0 ), " attractive numbers", newline ) )
END</lang>
{{out}}
<pre>
The attractve numbers up to 120
4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32 33 34
35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62 63 65 66 68
69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99
102 105 106 108 110 111 112 114 115 116 117 118 119 120
Found 74 attractive numbers
</pre>
 
=={{header|ALGOL W}}==
3,048

edits