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

Added Wren
m (→‎simple: two LIMITs)
(Added Wren)
Line 1,400:
<pre>
[1, 3, 25, 14, 14641, 44, 24137569, 70, 1089, 405, 819628286980801, 160, 22563490300366186081, 2752, 9801, 462, 21559177407076402401757871041, 1044, 740195513856780056217081017732809, 1520]
</pre>
 
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|Wren-math}}
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
import "/big" for BigInt
import "/fmt" for Fmt
 
var MAX = 33
var primes = Int.primeSieve(MAX * 5)
System.print("The first %(MAX) terms in the sequence are:")
for (i in 1..MAX) {
if (Int.isPrime(i)) {
var z = BigInt.new(primes[i-1]).pow(i-1)
Fmt.print("$2d : $i", i, z)
} else {
var count = 0
var j = 1
while (true) {
var cont = false
if (i % 2 == 1) {
var sq = j.sqrt.floor
if (sq * sq != j) {
j = j + 1
cont = true
}
}
if (!cont) {
if (Int.divisors(j).count == i) {
count = count + 1
if (count == i) {
Fmt.print("$2d : $d", i, j)
break
}
}
j = j + 1
}
}
}
}</lang>
 
{{out}}
<pre>
The first 33 terms in the sequence are:
1 : 1
2 : 3
3 : 25
4 : 14
5 : 14641
6 : 44
7 : 24137569
8 : 70
9 : 1089
10 : 405
11 : 819628286980801
12 : 160
13 : 22563490300366186081
14 : 2752
15 : 9801
16 : 462
17 : 21559177407076402401757871041
18 : 1044
19 : 740195513856780056217081017732809
20 : 1520
21 : 141376
22 : 84992
23 : 1658509762573818415340429240403156732495289
24 : 1170
25 : 52200625
26 : 421888
27 : 52900
28 : 9152
29 : 1116713952456127112240969687448211536647543601817400964721
30 : 6768
31 : 1300503809464370725741704158412711229899345159119325157292552449
32 : 3990
33 : 12166144
</pre>
 
9,488

edits