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

Add BCPL
(Added R. So short that I'm wondering if I've missed a point.)
(Add BCPL)
Line 166:
first 15 terms: 1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144
</pre>
 
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
 
manifest $( LENGTH = 15 $)
 
let divisors(n) = valof
$( let count = 0 and i = 1
while i*i <= n
$( if n rem i = 0 then
count := count + (i = n/i -> 1, 2)
i := i + 1
$)
resultis count
$)
 
let sequence(n, seq) be
$( let found = 0 and i = 1
for i=1 to n do seq!i := 0
while found < n
$( let divs = divisors(i)
if divs <= n & seq!divs = 0
$( found := found + 1
seq!divs := i
$)
i := i + 1
$)
$)
 
let start() be
$( let seq = vec LENGTH
sequence(LENGTH, seq)
for i=1 to LENGTH do writef("%N ", seq!i)
wrch('*N')
$)</lang>
{{out}}
<pre>1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144</pre>
 
=={{header|C}}==
2,114

edits