結果
| 問題 | No.534 フィボナッチフィボナッチ数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-23 23:17:53 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 2,000 ms |
| コード長 | 621 bytes |
| 記録 | |
| コンパイル時間 | 338 ms |
| コンパイル使用メモリ | 77,664 KB |
| 最終ジャッジ日時 | 2025-12-04 00:16:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 42 |
ソースコード
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
def matmul(A, B, mod):
return [
(A[0]*B[0] + A[1]*B[2]) % mod,
(A[0]*B[1] + A[1]*B[3]) % mod,
(A[2]*B[0] + A[3]*B[2]) % mod,
(A[2]*B[1] + A[3]*B[3]) % mod
]
def matpow(A, n, mod):
res = [1, 0, 0, 1]
while n > 0:
if n & 1:
res = matmul(res, A, mod)
A = matmul(A, A, mod)
n >>= 1
return res
def fib(n, mod):
A = [1, 1, 1, 0]
R = matpow(A, n-1, mod)
return R[0]
n = int(raw_input())
if n == 0:
print 0
exit(0)
m = fib(n, 2000000016)
x = fib(m, 10**9 + 7)
print x