Skip to content

Instantly share code, notes, and snippets.

@cjauvin
Created March 19, 2016 12:10
Show Gist options
  • Save cjauvin/a4baa6342ae9df7b462a to your computer and use it in GitHub Desktop.
Save cjauvin/a4baa6342ae9df7b462a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
"os"
"strconv"
)
func main() {
// Find bigger prime <= N
N, _ := strconv.Atoi(os.Args[1])
table := make([]bool, N+1)
table[0] = true
table[1] = true
M := int(math.Sqrt(float64(N))) + 1
for i := 2; i <= M; i++ {
if table[i] {
continue
}
for j := (i * i); j <= N; j += i {
table[j] = true
}
}
for i := N; ; i-- {
if !table[i] {
fmt.Println(i)
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment