2008-12-04から1日間の記事一覧

Problem 130

http://projecteuler.net/index.php?section=problems&id=130前問の結果を使えば、楽。 {-# OPTIONS_GHC -XBangPatterns #-} import Number count n = count' n (0,100) 1 count' n (q,r) !k | gcd 10 n /= 1 = n | (q,r)==(0,10) = k | otherwise = count' …

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…

Problem 128

http://projecteuler.net/index.php?section=problems&id=128六角形の絵を描いて考えてみると、調べるべき場所が案外少ないことに気づく。 import Number import Data.Maybe import Control.Arrow top n | all isPrime around = Just $ 2+3*n*(n-1) | otherw…

Problem 133

http://projecteuler.net/index.php?section=problems&id=133 これも同様。 オイラーの定理(だっけ?)と前を利用。 import Number hiding(powMod) powMod a n m | n < 3 = a^n `mod` m | otherwise = let (q,r) = divMod n 2 aq = powMod a q m in aq*aq*a…

Problem 132

http://projecteuler.net/index.php?section=problems&id=132 前と基本は同じ。 nがd桁で循環するなら 10^d=1 (mod n) これを利用。 import Number hiding(powMod) target = 10^9 powMod a n m | n < 3 = a^n `mod` m | otherwise = let (q,r) = divMod n 2 …