Jump to content

Sequence: smallest number with exactly n divisors: Difference between revisions

Added Go
m (typo)
(Added Go)
Line 14:
:*[[Sequence: smallest number greater than previous term with exactly n divisors]]
:*[[Sequence: nth number with exactly n divisors‎‎]]
 
=={{header|Go}}==
<lang go>package main
 
import "fmt"
 
func countDivisors(n int) int {
count := 0
for i := 1; i*i <= n; i++ {
if n%i == 0 {
if i == n/i {
count++
} else {
count += 2
}
}
}
return count
}
 
func main() {
const max = 15
seq := make([]int, max)
fmt.Println("The first", max, "terms of the sequence are:")
for i, n := 1, 0; n < max; i++ {
if k := countDivisors(i); k <= max && seq[k-1] == 0 {
seq[k-1] = i
n++
}
}
fmt.Println(seq)
}</lang>
 
{{out}}
<pre>
The first 15 terms of the sequence are:
[1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144]
</pre>
 
=={{header|Perl}}==
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.