Problem 207

Problem 207 - Project Euler
この問題はハマッタ。
Intが桁落ちしてた…
なかなか気がつかなかった。
2*2=4なのに…
2*2=1になってたじゃないか、これぐらい、気づこうよ。

import Data.List (findIndex)
import Data.Ratio ((%), denominator)

proportion :: Integer -> [Rational]
proportion n = [(n-1) % (2^n-2-m) | m <- [0..]]

p207 :: Integer -> Integer -> Integer
p207 n d = let Just m = findIndex ( < n%d) [(k-1) % (2^k-2) | k <- [2..]]
               a = denominator.last.takeWhile (< n%d).proportion.toInteger $ m+2
           in a*(a+1)
main :: IO ()
main = print $ p207 1 12345

もう、寝よう…