結果

問題 No.786 京都大学の過去問
ユーザー かりあげクンかりあげクン
提出日時 2020-09-28 01:45:16
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 595 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 164,748 KB
実行使用メモリ 7,104 KB
最終ジャッジ日時 2023-09-13 07:48:12
合計ジャッジ時間 2,986 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

--------------------------------------------------------------------------------
-- https://blog.miz-ar.info/2019/01/fast-fibonacci/
--------------------------------------------------------------------------------
fastDoubling :: Int -> (Integer, Integer)
fastDoubling 0 = (0, 1)
fastDoubling 1 = (1, 1)
fastDoubling i
  = let (a, b) = fastDoubling (i `quot` 2)
    in if even i
       then (a * (2 * b - a), a * a + b * b)
       else (a * a + b * b, b * (2 * a + b))

fib :: Int -> Integer
fib i = case fastDoubling i of
          (a, _) -> a
main :: IO ()
main = readLn >>= print . fib . pred
0