Attractive numbers: Difference between revisions

Content added Content deleted
(Using Sieve of Eratosthenes module)
(Add CLU)
Line 788: Line 788:
</pre>
</pre>


=={{header|CLU}}==
<lang clu>sieve = proc (max: int) returns (array[bool])
prime: array[bool] := array[bool]$fill(1,max,true)
prime[1] := false
for p: int in int$from_to(2, max/2) do
if prime[p] then
for c: int in int$from_to_by(p*p, max, p) do
prime[c] := false
end
end
end
return(prime)
end sieve

n_factors = proc (n: int, prime: array[bool]) returns (int)
count: int := 0
i: int := 2
while i<=n do
if prime[i] then
while n//i=0 do
count := count + 1
n := n/i
end
end
i := i + 1
end
return(count)
end n_factors

start_up = proc ()
MAX = 120
po: stream := stream$primary_output()
prime: array[bool] := sieve(MAX)
col: int := 0
for i: int in int$from_to(2, MAX) do
if prime[n_factors(i,prime)] then
stream$putright(po, int$unparse(i), 4)
col := col + 1
if col//15 = 0 then stream$putl(po, "") end
end
end
end start_up</lang>
{{out}}
<pre> 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</pre>
=={{header|COBOL}}==
=={{header|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
<lang cobol> IDENTIFICATION DIVISION.
Line 883: Line 931:
92 93 94 95 98 99 102 105 106 108 110 111 112 114 115 116 117 118
92 93 94 95 98 99 102 105 106 108 110 111 112 114 115 116 117 118
119 120</pre>
119 120</pre>



=={{header|Common Lisp}}==
=={{header|Common Lisp}}==