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 /= | s <-step] residue u p = [n | n <-[..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 <-[..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
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)