結果
問題 |
No.718 行列のできるフィボナッチ数列道場 (1)
|
ユーザー |
![]() |
提出日時 | 2022-09-06 23:28:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 524 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 52,608 KB |
最終ジャッジ日時 | 2024-11-21 23:31:08 |
合計ジャッジ時間 | 2,105 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
def dot(A, B, mod): res = [[0]*2 for _ in range(2)] for i in range(2): for j in range(2): for k in range(2): res[i][j] += A[i][k]*B[k][j] res[i][j] %= mod return res cal = [] cal.append([[1,1],[1,0]]) for i in range(40): c = dot(cal[-1], cal[-1], 10**9+7) cal.append(c) N = int(input()) mod = 10**9+7 n = bin(N)[2:] res = [[1,0],[0,1]] for i in range(len(n)): if n[-1-i]=='1': res = dot(cal[i], res, mod) print((res[0][0]*res[1][0])%mod)