Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Anti-primes/Go/anti-primes.go
Normal file
31
Task/Anti-primes/Go/anti-primes.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue