Problem 129
http://projecteuler.net/index.php?section=problems&id=129
これも前に考えたことがある。
111...1 = n*mとする(n
{-# OPTIONS_GHC -XBangPatterns #-} import Data.List count n (q,r) !k | gcd 10 n /= 1 = 0 | (q,r)==(0,10) = k | otherwise = count n (divMod (10*r) (9*n))$ k+1 main = print.find((>10^6).count')$[10^6..] where count' n = count n (0,100) 1
!mで正格に評価するのがポイント(だと思っている)。
mだとスタックオーバーフロー