Jump to content

Erdős-Nicolas numbers: Difference between revisions

→‎{{header|Wren}}: Added a second version (C++/Algol 68 translation).
(→‎{{header|Wren}}: Added a second version (C++/Algol 68 translation).)
Line 749:
 
=={{header|Wren}}==
===Version 1===
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascript">import "./math" for Int
Line 788 ⟶ 789:
714240 from 113
1571328 from 115
</pre>
 
===Version 2===
{{trans|C++}}
This takes 7 minutes to run (about 10 times slower than C++) but finds 2 more numbers, albeit not in strictly increasing order.
 
If `maxNum` is set to 2 million, then it finds the first 8 in about 5.2 seconds which is more than 10 times faster than Version 1's 58 seconds.
<syntaxhighlight lang="ecmascript">import "./fmt" for Fmt
 
var maxNum = 1e8
var dsum = List.filled(maxNum+1,1)
var dcount = List.filled(maxNum+1, 1)
for (i in 2..maxNum) {
var j = i + i
while (j <= maxNum) {
if (dsum[j] == j) {
Fmt.print("$8d equals the sum of its first $d divisors", j, dcount[j])
}
dsum[j] = dsum[j] + i
dcount[j] = dcount[j] + 1
j = j + i
}
}</syntaxhighlight>
 
{{out}}
<pre>
24 equals the sum of its first 6 divisors
2016 equals the sum of its first 31 divisors
8190 equals the sum of its first 43 divisors
42336 equals the sum of its first 66 divisors
45864 equals the sum of its first 66 divisors
714240 equals the sum of its first 113 divisors
392448 equals the sum of its first 68 divisors
1571328 equals the sum of its first 115 divisors
61900800 equals the sum of its first 280 divisors
91963648 equals the sum of its first 142 divisors
</pre>
 
9,483

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.