結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,044 KB
testcase_01 AC 3 ms
6,884 KB
testcase_02 AC 3 ms
6,908 KB
testcase_03 AC 3 ms
6,884 KB
testcase_04 AC 2 ms
6,872 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 . succ
0