Erdős-Nicolas numbers: Difference between revisions
m
syntax highlighting fixup automation
(→{{header|Julia}}: slightly more efficient) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 26:
=={{header|ALGOL 68}}==
Builds tables of proper divisor counts and sums and finds the numbers whilst doing it. This means that the numbers are not found in numerical order.
<
# first k proper divisors but k is not the count of all their proper #
# divisors ( so the numbers aren't perfect ) #
Line 51:
OD
OD
END</
{{out}}
<pre>
Line 80:
=={{header|J}}==
Implementation:<
erdosnicolas=: {{ y e. +/\ _2}. divisors y }}"0</
24 2016 8190 42336 45864 392448 714240 1571328
(,. 1++/\@divisors i. ])@>24 2016 8190 42336 45864 392448 714240 1571328
Line 91:
392448 68
714240 113
1571328 115</
=={{header|Julia}}==
<
function isErdősNicolas_with_k(n)
Line 116:
isEN && println(lpad(n, 8), " equals the sum of its first $k divisors.")
end
</
<pre>
24 equals the sum of its first 6 divisors.
Line 130:
=={{header|Phix}}==
{{trans|Wren}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">erdos_nicolas</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
Line 153:
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">2</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</
Aside: The default for factors() is to return neither 1 nor n, though you can change that if you want, ie ",1" -> 1 and n; ",-1" -> 1 but not n.<br>
Output same as Julia
=={{header|Raku}}==
<syntaxhighlight lang="raku"
sub is-Erdős-Nicolas ($n) {
Line 172:
exit if ++$count >= 8;
}
}</
{{out}}
<pre> 24 == sum of its first 6 divisors
Line 185:
=={{header|Wren}}==
{{libheader|Wren-math}}
<
var erdosNicolas = Fn.new { |n|
Line 211:
}
n = n + 2
}</
{{out}}
|