Created
November 30, 2014 07:27
-
-
Save akihiro4chawon/f38603e39f4651f52ab5 to your computer and use it in GitHub Desktop.
久しぶりにリハビリ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.Array | |
-- mod m としたフィボナッチ数列 (繰り返しとなる時点で打ち切り) | |
fibMod :: Int -> [Int] | |
fibMod m = 0 : fibMod' 1 1 | |
where | |
fibMod' 0 1 = [] | |
fibMod' x y = x : fibMod' y (mod (x + y) m) | |
-- フィボナッチ数列の第n番目の値を返す表を作成する | |
createTable :: Int -> Array Int Int | |
createTable m = listArray (0, length fibModList) fibModList | |
where | |
fibModList = fibMod m | |
-- フィボナッチ数列の第n番目の値 | |
fibTermNthMod :: Int -> Int -> Int | |
fibTermNthMod m n = table ! mod n size | |
where | |
table = createTable m | |
size = snd $ bounds table | |
main :: IO () | |
main = getLine >> interact interaction | |
where | |
interaction = unlines . map perLine . lines | |
perLine = show . fibTermNthMod 1000 . read |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment