Skip to content

Instantly share code, notes, and snippets.

@romanitalian
Created December 5, 2020 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save romanitalian/a1c81a8abe3999ab8ea99b0722668687 to your computer and use it in GitHub Desktop.
Save romanitalian/a1c81a8abe3999ab8ea99b0722668687 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
"time"
)
func isPrime(num int) bool {
if num == 2 {
return true
}
if num == 1 || num%2 == 0 {
return false
}
to := int(math.Sqrt(float64(num)))
for div := 3; div <= to; div += 2 {
if num%div == 0 {
return false
}
}
return true
}
func do(N int) {
for i := 0; i < N; i++ {
prime := isPrime(i)
if prime {
// fmt.Printf("%+v: %+v\n", i, prime)
}
}
}
func main() {
st := time.Now()
do(10_000_000)
fmt.Printf("%+v\n", time.Since(st))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment