Project Euler 解答

Project Euler Problem 045

Project Euler Problem 045

import Data.List import Data.Maybe -- 逆数を利用した判定 istrian :: Integer -> Bool istrian n = r - (fromIntegral $ floor r) < 1e-5 where r = (sqrt((fromIntegral n)*8.0+1.0)-1.0)/2.0 ispenta :: Integer -> Bool ispenta n = r - (fromIntegral $ floor r) < 1e-5 where r = (sqrt((fromIntegral n)*24+1.0)+1.0)/6.0 ishexag :: Integer -> Bool ishexag n = r - (fromIntegral $ floor r) < 1e-5 where r = (sqrt((fromIntegral n)*8.0+1.0)+1.0)/4.0 -- 六角数のリスト。六角数は三角数でもある hexas :: [Integer] hexas = map (\n-> n*(2*n-1)) [144..] ans1 :: Integer ans1 = fromJust $ find ispenta hexas -- 1533776805 main :: IO () main = print ans1

since 2013