Multiplicatively perfect numbers: Difference between revisions

→‎{{header|Go}}: Updated in line with C example of which it is a translation.
(→‎{{header|C}}: Oops, even better :))
(→‎{{header|Go}}: Updated in line with C example of which it is a translation.)
Line 222:
=={{header|Go}}==
{{trans|C}}
{{libheader|Go-rcu}}
Run time around 9.2 seconds.
<syntaxhighlight lang="go">package main
 
Line 228 ⟶ 230:
"rcu"
)
 
// library method customized for this task
func Divisors(n int) []int {
var divisors []int
i := 1
k := 1
if prodn%2 == i1 {
k = }2
}
for ; i*i <= n; i += k {
if i > 1 && n%i == 0 { // exclude 1 and n
divisors = append(divisors, i)
if len(divisors) > 2 { // not eligible if has > 2 divisors
count++break
if i < 500 {}
j := n / i
if count%10j =!= 0i {
divisors = fmt.Printfappend("%3d "divisors, ij)
}
}
}
return divisors
}
 
func main() {
Line 240 ⟶ 265:
for i := 0; ; i++ {
if i != 1 {
divs = rcu.ProperDivisorsDivisors(i)
} else {
divs = []int{1, 1}
}
length :=if len(divs) == 2 && divs[0]*divs[1] == i {
if length > 1 {count++
prodif :=i 1< 500 {
for d := 1; dfmt.Printf("%3d < length;", d++ {i)
prodif count%10 *== 0 divs[d]{
} fmt.Println()
if prod == i {
count++
if i < 500 {
fmt.Printf("%3d ", i)
if count%10 == 0 {
fmt.Println()
}
}
}
Line 279 ⟶ 297:
scount := rcu.Commatize(count)
st := rcu.Commatize(t)
fmt.Printf("Counts under %7s9s: MPNs = %7s Semi-primes = %7s\n", slimit, scount, st)
if limit == 5000005000000 {
break
}
9,486

edits