This package provides some functions for working with prime numbers.
package main
import (
"fmt"
prime "github.com/theTardigrade/golang-prime"
)
func main() {
var magicNumber int64 = 3
fmt.Println(prime.Is(magicNumber)) // true
fmt.Println(prime.Next(magicNumber)) // 5, true
fmt.Println(prime.Prev(magicNumber)) // 2, true
fmt.Println("*****")
magicNumber = 120
fmt.Println(prime.Is(magicNumber)) // false
fmt.Println(prime.Next(magicNumber)) // 127, true
fmt.Println(prime.Prev(magicNumber)) // 113, true
fmt.Println("*****")
magicNumber = 2
fmt.Println(prime.Is(magicNumber)) // true
fmt.Println(prime.Next(magicNumber)) // 3, true
fmt.Println(prime.Prev(magicNumber)) // 0, false
fmt.Println("*****")
magicNumber = 1_000_000_000_000
fmt.Println(prime.Is(magicNumber)) // false
fmt.Println(prime.Next(magicNumber)) // 1000000000001, true
fmt.Println(prime.Prev(magicNumber)) // 999999999997, true
}
If you use this package, or find any value in it, please consider donating: