Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions

Added Wren
(→‎{{header|C++}}: Added alternative, Pascal translation)
(Added Wren)
Line 986:
<pre>
[1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624]
</pre>
 
=={{header|Wren}}==
{{trans|Phix}}
{{libheader|Wren-math}}
<lang ecmascript>import "/math" for Int
 
var limit = 24
var res = List.filled(limit, 0)
var next = 1
var n = 1
while (next <= limit) {
var k = Int.divisors(n).count
if (k == next) {
res[k-1] = n
next = next + 1
if (next > 4 && Int.isPrime(next)) n = 2.pow(next-1) - 1
}
n = n + 1
}
System.print("The first %(limit) terms are:")
System.print(res)</lang>
 
{{out}}
<pre>
The first 24 terms are:
[1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624, 4632, 65536, 65572, 262144, 262192, 263169, 269312, 4194304, 4194306]
</pre>
 
9,476

edits