22 lines
520 B
Haskell
22 lines
520 B
Haskell
module Primes ( aspGetNextPrime, aspIsPrime, aspPrimes ) where
|
|
import Problems ( kth )
|
|
|
|
aspGetNextPrime :: Int -> Int
|
|
aspGetNextPrime 1 = 2
|
|
aspGetNextPrime 2 = 3
|
|
aspGetNextPrime n
|
|
| otherwise = aspGetNextPrime (n + 2)
|
|
|
|
aspIsPrime :: Int -> Bool
|
|
aspIsPrime 1 = False
|
|
aspIsPrime n = mod n (aspGetNextPrime 1) == 0
|
|
-- where
|
|
-- recMod
|
|
|
|
--aspPrimeFactors :: Int -> [Int]
|
|
--aspPrimeFactors 1 = [1]
|
|
|
|
--aspPrimes :: (Integral Int) => [Int]
|
|
aspPrimes = sieve [2..]
|
|
where sieve (x:xs) = [ x | x <- xs, x mod p == 0]
|