Anti-primes: Difference between revisions

Added Go
(Added Sidef)
(Added Go)
Line 10:
;Related task:
::*   [[Factors of an integer]]
 
=={{header|Go}}==
Simple brute force approach which is quick enough here.
<lang go>package main
 
import "fmt"
 
func countDivisors(n int) int {
if n < 2 {
return 1
}
count := 2 // 1 and n
for i := 2; i <= n/2; i++ {
if n%i == 0 {
count++
}
}
return count
}
 
func main() {
fmt.Println("The first 20 anti-primes are:")
maxDiv := 0
count := 0
for n := 1; count < 20; n++ {
d := countDivisors(n)
if d > maxDiv {
fmt.Printf("%d ", n)
maxDiv = d
count++
}
}
fmt.Println()
}</lang>
 
{{out}}
<pre>
The first 20 anti-primes are:
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
 
=={{header|Pascal}}==
Line 63 ⟶ 103:
end.</lang>;Output:<pre>1(1),2(2),4(3),6(4),12(6),24(8),36(9),48(10),60(12),120(16),180(18),240(20),
360(24),720(30),840(32),1260(36),1680(40),2520(48),5040(60),7560(64)</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.11}}
9,490

edits