Multiplicatively perfect numbers: Difference between revisions
→{{header|Wren}}: Changed to include '1' as an MPN.
(Added a note to make the inclusion of '1' as a MPN optional.) |
(→{{header|Wren}}: Changed to include '1' as an MPN.) |
||
Line 471:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
This includes '1' as an MPN.
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./fmt" for Fmt
Line 479 ⟶ 480:
System.print("Multiplicatively perfect numbers under %(limit):")
while (true) {
var pd = (i != 1) ? Int.properDivisors(i).skip(1) : [1, 1]
if (pd.count > 1 && Nums.prod(pd) == i) {
count = count + 1
Line 485 ⟶ 486:
var pds = pd.map { |d| Fmt.d(3, d) }.join(" x ")
Fmt.write("$3d = $s ", i, pds)
if (count %
}
}
if (i == 499) System.print(
if (i >= limit - 1) {
var squares = Int.primeSieve((limit - 1).sqrt.floor).count
var cubes = Int.primeSieve((limit - 1).cbrt.floor).count
var count2 = count + squares - cubes - 1
Fmt.print("Counts under $,7d: MPNs = $,7d Semi-primes = $,7d", limit, count, count2)
if (limit == 500000) return
Line 503 ⟶ 504:
<pre>
Multiplicatively perfect numbers under 500:
1 = 1 x 1 6 = 2 x 3 8 = 2 x 4 10 = 2 x 5 14 = 2 x 7
15 = 3 x 5 21 = 3 x 7 22 = 2 x 11 26 = 2 x 13 27 = 3 x 9
Counts under 500: MPNs =
Counts under 5,000: MPNs = 1,
Counts under 50,000: MPNs = 12,
Counts under 500,000: MPNs = 108,
</pre>
|