blob: 34b3a568b709ff534db64a5c8044145eb9037f3e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
{-# LANGUAGE ParallelArrays #-}
{-# OPTIONS -fvectorise #-}
module PrimesVect (primesVect)
where
import Data.Array.Parallel
import Data.Array.Parallel.Prelude.Int
import qualified Prelude
primesVect:: Int -> PArray Int
primesVect n = toPArrayP (primesVect' n)
primesVect':: Int -> [:Int:]
primesVect' n
| n == 1 = emptyP
| n == 2 = singletonP 2
| otherwise = sps +:+ [: i | i <- enumFromToP (sq+1) n, notMultiple sps i:]
where
sps = primesVect' sq
sq = sqrt n
notMultiple :: [:Int:] -> Int -> Bool
notMultiple ps i = andP [: mod i p /= 0 | p <- ps:]
|