Problem 234

234 Semidivisible numbers

Problem 234 – Project Euler

prime sqaure root という,素数の世界でのルートについての問題.

lps, ups が決まると範囲が決まるので,それを利用.

import Number (primes)
p234 :: Integer -> Integer
p234 n = sum.filter ( <= n ).concat.zipWith semiIn (takeWhile (<= u) primes) $ tail primes
where u = floor.sqrt.fromIntegral $ n
semiIn :: (Num a, Enum a) => a -> a -> [a]
semiIn l u = filter ( /= l * u )  $ semiL ++ semiU
where semiL = [l * (l+1), l * (l+2)..u * u - 1]
semiU = reverse [u * (u-1), u * (u-2)..l * l + 1]
main :: IO ()
main = print.p234 $ 999966663333
More Reading
Newer// Problem 233
Older// Problem 235