[[ProjectEular]]

 -- Problem 23
 
 module Main (main) where
 
 import Array
 import qualified Common as C (proper_divisors)
 
 main :: IO ()
 main = print $ problem23 28123
 
 problem23 :: Int -> Int
 problem23 max_n = sum [ n | n <- [1..max_n], null (abundant_pairs array n) ]
     where array = listArray (1,max_n) (map is_abundant [1..max_n])
 
 abundant_pairs :: Array Int Bool -> Int -> [(Int,Int)]
 abundant_pairs array n = [ (x,(n-x)) | x <- [1..(div n 2)], array ! x, array ! (n-x) ]
 
 is_abundant :: Int -> Bool
 is_abundant n = sum (C.proper_divisors n) > n


トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS