Numbers whose count of divisors is prime: Difference between revisions

Add CLU
(Added solution for Action!)
(Add CLU)
Line 252:
Count: 79
</pre>
 
=={{header|CLU}}==
<lang clu>% Find the amount of divisors for 1..N
div_counts = proc (n: int) returns (sequence[int])
divs: array[int] := array[int]$fill(1,n,1)
for d: int in int$from_to(2, n) do
for m: int in int$from_to_by(d, n, d) do
divs[m] := divs[m] + 1
end
end
return(sequence[int]$a2s(divs))
end div_counts
 
% Find maximum element of sequence
max = proc (seq: sequence[int]) returns (int)
n: int := 0
for i: int in sequence[int]$elements(seq) do
if i>n then n:=i end
end
return(n)
end max
 
% Sieve primes up to N
sieve = proc (n: int) returns (sequence[bool])
prime: array[bool] := array[bool]$fill(1,n,true)
prime[1] := false
for p: int in int$from_to(2, n/2) do
for c: int in int$from_to_by(p*p, n, p) do
prime[c] := false
end
end
return(sequence[bool]$a2s(prime))
end sieve
 
start_up = proc ()
MAX_N = 100000
po: stream := stream$primary_output()
div_count: sequence[int] := div_counts(MAX_N)
prime: sequence[bool] := sieve(max(div_count))
count: int := 0
for i: int in int$from_to(1, MAX_N) do
dc: int := div_count[i]
if dc ~= 2 cand prime[dc] then
stream$putright(po, int$unparse(i), 8)
count := count + 1
if count//10 = 0 then stream$putl(po, "") end
end
end
stream$putl(po, "\nFound " || int$unparse(count) || " numbers.")
end start_up</lang>
{{out}}
<pre> 4 9 16 25 49 64 81 121 169 289
361 529 625 729 841 961 1024 1369 1681 1849
2209 2401 2809 3481 3721 4096 4489 5041 5329 6241
6889 7921 9409 10201 10609 11449 11881 12769 14641 15625
16129 17161 18769 19321 22201 22801 24649 26569 27889 28561
29929 32041 32761 36481 37249 38809 39601 44521 49729 51529
52441 54289 57121 58081 59049 63001 65536 66049 69169 72361
73441 76729 78961 80089 83521 85849 94249 96721 97969
Found 79 numbers.</pre>
 
=={{header|F_Sharp|F#}}==
Line 263 ⟶ 323:
4 9 16 25 49 64 81 121 169 289 361 529 625 729 841 961 1024 1369 1681 1849 2209 2401 2809 3481 3721 4096 4489 5041 5329 6241 6889 7921 9409 10201 10609 11449 11881 12769 14641 15625 16129 17161 18769 19321 22201 22801 24649 26569 27889 28561 29929 32041 32761 36481 37249 38809 39601 44521 49729 51529 52441 54289 57121 58081 59049 63001 65536 66049 69169 72361 73441 76729 78961 80089 83521 85849 94249 96721 97969
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
2,095

edits