結果

問題 No.786 京都大学の過去問
ユーザー かりあげクンかりあげクン
提出日時 2020-09-28 01:44:34
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 614 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 169,408 KB
実行使用メモリ 6,964 KB
最終ジャッジ日時 2023-09-13 07:47:25
合計ジャッジ時間 2,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,892 KB
testcase_01 AC 3 ms
6,948 KB
testcase_02 AC 2 ms
6,908 KB
testcase_03 AC 2 ms
6,964 KB
testcase_04 AC 3 ms
6,892 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 = do
  n <- readLn :: IO Int
  print $ fib (n + 1)
0