Project Euler Problem 070
import Data.List primes :: [Integer] primes = 2:f [3] [3,5..] where f (x:xs) ys = ps ++ f (xs++ps) [z | z<-qs,z`rem`x/=0] where (ps,qs) = span (< x*x) ys factor :: Integer -> [Integer] factor nn = factorimpl nn primes where factorimpl n pri@(p:xs) = if p*p>n then [n] else if n`rem` p == 0 then p:factorimpl (n `quot` p) pri else factorimpl n xs limit :: Integer limit = 10^(7::Integer) ans1 :: Integer ans1 = snd $ minimum a where a = [((fromIntegral pq / fromIntegral tot),pq) | let lim = takeWhile(<=(limit`quot`2)) primes, --最小の素数は2 p<-filter ((==2).(`rem`3)) lim, --euler p,qは3を法として2 q<-filter (\x -> ((x `rem` 3) == 2)&&((p+x-1)`mod`9==0)) $ takeWhile (\x -> x