Multiplicatively perfect numbers: Difference between revisions

Added Go
(→‎{{header|Wren}}: Now uses primeCount method rather than a sieve.)
(Added Go)
Line 143:
{{out}}
<pre>Similar to Ring entry.</pre>
 
=={{header|Go}}==
{{trans|C}}
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"rcu"
)
 
func main() {
count := 0
limit := 500
s := 3
c := 3
squares := 1
cubes := 1
fmt.Printf("Multiplicatively perfect numbers under %d:\n", limit)
var divs []int
for i := 0; ; i++ {
if i != 1 {
divs = rcu.ProperDivisors(i)
} else {
divs = []int{1, 1}
}
length := len(divs)
if length > 1 {
prod := 1
for d := 1; d < length; d++ {
prod *= divs[d]
}
if prod == i {
count++
if i < 500 {
fmt.Printf("%3d ", i)
if count%10 == 0 {
fmt.Println()
}
}
}
}
if i == 499 {
fmt.Println()
}
if i >= limit-1 {
var j, k int
for j = s; j*j < limit; j += 2 {
if rcu.IsPrime(j) {
squares++
}
}
for k = c; k*k*k < limit; k += 2 {
if rcu.IsPrime(k) {
cubes++
}
}
t := count + squares - cubes - 1
slimit := rcu.Commatize(limit)
scount := rcu.Commatize(count)
st := rcu.Commatize(t)
fmt.Printf("Counts under %7s: MPNs = %7s Semi-primes = %7s\n", slimit, scount, st)
if limit == 500000 {
break
}
s, c = j, k
limit *= 10
}
}
}</syntaxhighlight>
 
{{out}}
<pre>
Same as C example.
</pre>
 
=={{header|J}}==
9,488

edits