Erdős-Nicolas numbers: Difference between revisions
Content added Content deleted
(Created Nim solution.) |
|||
Line 534: | Line 534: | ||
714240 equals the sum of its first 113 divisors. |
714240 equals the sum of its first 113 divisors. |
||
1571328 equals the sum of its first 115 divisors. |
1571328 equals the sum of its first 115 divisors. |
||
</pre> |
|||
=={{header|Nim}}== |
|||
{{trans|Go}} |
|||
To get better performances, we use 32 bits integers rather than 64 bits integers. We got the best (and excellent) execution time with compilation command: <code>nim c -d:release -d:lto --gc:boehm erdos_nicolas_numbers.nim</code> |
|||
<syntaxhighlight lang="Nim">import std/[sequtils, strformat] |
|||
proc main() = |
|||
const MaxNumber = 100_000_000i32 |
|||
var dsum, dcount = repeat(1'i32, MaxNumber + 1) |
|||
for i in 2i32..MaxNumber: |
|||
for j in countup(i + i, MaxNumber, i): |
|||
if dsum[j] == j: |
|||
echo &"{j:>8} equals the sum of its first {dcount[j]} divisors" |
|||
inc dsum[j], i |
|||
inc dcount[j] |
|||
main() |
|||
</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> |
</pre> |
||