package main
import "fmt"
import "math"
import "flag"
func main() {
var N int
flag.IntVar(&N, "N", 100, "")
numb := make([]bool, N)
limit := int(math.Sqrt(float64(N))) + 1
for i := 2; i < limit; i++ {
if !numb[i] {
for j := i * i; j < N; j += i {
numb[j] = true
}
for i := 2; i < N; i++ {
fmt.Printf("%d\n", i)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
package main
import "fmt"
import "math"
import "flag"
func main() {
var N int
flag.IntVar(&N, "N", 100, "")
numb := make([]bool, N)
limit := int(math.Sqrt(float64(N))) + 1
for i := 2; i < limit; i++ {
if !numb[i] {
for j := i * i; j < N; j += i {
numb[j] = true
}
}
}
for i := 2; i < N; i++ {
if !numb[i] {
fmt.Printf("%d\n", i)
}
}
}