結果

問題 No.534 フィボナッチフィボナッチ数
コンテスト
ユーザー aimy
提出日時 2017-06-24 10:49:21
言語 Haskell
(9.14.1 + ACL)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 385 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,995 ms
コンパイル使用メモリ 198,144 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-09 23:07:06
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

q = 10^9+7

fib :: Int -> Int -> Int
fib modulo n = fst (fibr (0,1) n)
 where
  tpq (p,q) (a,b) = (mod (p*a + q*b) modulo, mod (q*a + (p+q)*b) modulo)
  fibr pq@(p,q) n
   | n < 1 = (0,1)
   | even n = fibr (p^2 + q^2, 2*p*q + q^2) (div n 2)
   | otherwise = tpq pq (fibr pq (n-1))

main = do
 n <- readLn :: IO Integer
 print $ (fib q . fib q) (fromIntegral (mod n (2 * (10^9) + 16)))
0