Sequence: smallest number with exactly n divisors: Difference between revisions

Add Cowgol
(Add Modula-2)
(Add Cowgol)
Line 288:
1 2 4 6 16 12 64 24 36 48 1024 60 0 192 144
</pre>
 
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
 
const AMOUNT := 15;
typedef I is uint16;
 
sub divisors(n: I): (count: I) is
var i: I := 1;
count := 0;
while i*i <= n loop
if n%i == 0 then
if n/i == i then
count := count + 1;
else
count := count + 2;
end if;
end if;
i := i + 1;
end loop;
end sub;
 
var seq: I[AMOUNT+1];
MemZero(&seq as [uint8], @bytesof seq);
 
var found: I := 0;
var i: I := 1;
 
while found < AMOUNT loop
var divs := divisors(i) as @indexof seq;
if divs <= AMOUNT and seq[divs] == 0 then
found := found + 1;
seq[divs] := i;
end if;
i := i + 1;
end loop;
 
var j: @indexof seq := 1;
while j <= AMOUNT loop
print_i16(seq[j]);
print_char(' ');
j := j + 1;
end loop;
print_nl();</lang>
{{out}}
<pre>1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144</pre>
 
=={{header|F_Sharp|F#}}==
2,114

edits