Problem 146
http://projecteuler.net/index.php?section=problems&id=146
import Number import Data.List import Control.Monad step = [1,3,7,9,13,27] indivisible p n = and [mod (n*n+s) p /= 0 | s <-step] residue u p = [n | n <-[0..min u (p-1)], indivisible p n] residues u [p] = residue u p residues u (p:ps) = [k*q+n | n <-residues u ps, k <-[0..min (p-1) $ div (u-n) q], indivisible p $ mod (k*q+n) p] where q = product ps nextPrime p = head.filter isPrime' $[p+1..] isConsPrimes (p:ps) = isPrime' p && (and.zipWith (==) ps .map nextPrime) (p:ps) isPrimePattern n = isConsPrimes.map (+n*n)$step p146 n = [m | m <- residues n smallPrimes, isPrimePattern m] where smallPrimes = reverse.takeWhile(<100)$primes main = print.sum.p146$150*10^6