Skip to content

Instantly share code, notes, and snippets.

@sukeesh
Created May 24, 2020 18:42
Show Gist options
  • Save sukeesh/3fec59b9025978dbf92b6b6e66b92e6e to your computer and use it in GitHub Desktop.
Save sukeesh/3fec59b9025978dbf92b6b6e66b92e6e to your computer and use it in GitHub Desktop.
package main
import(
"strconv"
"os"
)
func generate_sieve(n int) {
isPrime := make([]bool, n + 1)
for i, _ := range (isPrime) {isPrime[i] = true}
isPrime[0] = false
isPrime[1] = false
isPrime[2] = true
i := 2
for i <= n {
if isPrime[i] {
j := 2
for i * j <= n {
isPrime[i * j] = false
j = j + 1
}
}
i = i + 1
}
}
func main() {
n, _ := strconv.Atoi(os.Args[1])
generate_sieve(n)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment