Problem 174
コンテンツ
http://projecteuler.net/index.php?section=problems&id=174
まぁ、これもさっきと大して変わらない(と思う、もっと良い解法があるかも)。
import Data.List import Data.Array.IO n :: Integer n = 10^6 lamina :: Integer -> [Integer] lamina h = [l^2-h^2 | l <- [h+2,h+4..floor.sqrt.fromIntegral $ n + h^2]] main :: IO () main = do l <- newArray (1,fromIntegral n) :: IO (IOUArray Int Int) mapM_ (incArray l).map fromIntegral.concatMap lamina $ [1..div n 2 - 2] print.length.filter (x -> 1<=x && x<=10) =<< getElems l where incArray ar x = readArray ar x >>= writeArray ar x.succ
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)