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
}
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
j := n / i
}
}
}
return divisors
}
func main() {
Line 240 ⟶ 265:
for i := 0; ; i++ {
if i != 1 {
divs =
} else {
divs = []int{1, 1}
}
▲ if prod == i {
▲ count++
▲ if i < 500 {
▲ fmt.Printf("%3d ", i)
▲ if count%10 == 0 {
▲ }
}
}
Line 279 ⟶ 297:
scount := rcu.Commatize(count)
st := rcu.Commatize(t)
fmt.Printf("Counts under %
if limit ==
break
}
|