FVA27TNS75OQUHWRPADSLQWYSKUDDNKZLABYFYDJ652C3HNAEFTAC
// Package prime is for prime related tasks.
package prime
const max = 104743 // biggest test input
type sieveMap map[int]bool
var mysieve = genPrimes(max)
// genPrimes makes non-primes true.
// https://www.geeksforgeeks.org/sieve-of-eratosthenes
func genPrimes(n int) sieveMap {
sieve := make(sieveMap)
for p := 2; p*p <= n; p++ {
for i := p * p; i <= n; i += p {
sieve[i] = true
}
}
return sieve
}
// Nth returns the n-th prime number or false on error.
func Nth(n int) (int, bool) {
if n < 1 {
return 0, false
}
count, i := 0, 0
for i = 2; count < n; i++ {
if !mysieve[i] {
count++
}
}
return i - 1, true
}