Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "strconv"
- "time"
- )
- func main() {
- var max_n = int32(20_000)
- if len(os.Args) > 1 {
- if n, err := strconv.Atoi(os.Args[1]); err == nil {
- max_n = int32(n)
- }
- }
- t := time.Now()
- primes := make([]int32, 1, max_n)
- primes[0] = 2
- var check int32 = 3
- var index int32 = 1
- for index < max_n {
- is_prime := true
- for _, prime := range primes {
- if (check % prime) == 0 {
- is_prime = false
- break
- }
- }
- if is_prime {
- primes = append(primes, check)
- index += 1
- }
- check += 2
- }
- fmt.Println(len(primes))
- fmt.Println(time.Since(t))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement