結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー kurimupykurimupy
提出日時 2020-06-15 18:04:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 65 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 29,580 KB
最終ジャッジ日時 2023-09-16 10:29:41
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
29,380 KB
testcase_01 AC 123 ms
29,504 KB
testcase_02 AC 122 ms
29,468 KB
testcase_03 AC 126 ms
29,384 KB
testcase_04 AC 123 ms
29,440 KB
testcase_05 AC 123 ms
29,504 KB
testcase_06 AC 123 ms
29,556 KB
testcase_07 AC 123 ms
29,440 KB
testcase_08 AC 123 ms
29,384 KB
testcase_09 AC 122 ms
29,484 KB
testcase_10 AC 123 ms
29,492 KB
testcase_11 AC 124 ms
29,448 KB
testcase_12 AC 122 ms
29,404 KB
testcase_13 AC 122 ms
29,492 KB
testcase_14 AC 123 ms
29,416 KB
testcase_15 AC 122 ms
29,580 KB
testcase_16 AC 123 ms
29,516 KB
testcase_17 AC 122 ms
29,524 KB
testcase_18 AC 122 ms
29,444 KB
testcase_19 AC 122 ms
29,504 KB
testcase_20 AC 123 ms
29,432 KB
testcase_21 AC 122 ms
29,572 KB
testcase_22 AC 122 ms
29,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#Fibonacchi sequence
import numpy as np
N = int(input())
A = np.array([[1, 1], [1, 0]],dtype="int64")

mod =10 **9 + 7
def mat_f(X):
    if X == 0:
        return np.array([1, 0], [0, 1])
    elif X == 1:
        return A
    else:
        if X % 2 == 0:
            S = mat_f(X//2)
            S%=mod
            return np.dot(S, S)
        else:
            S = mat_f(X//2)
            S%=mod
            return np.dot(np.dot(S, S), A)


mat = np.dot(mat_f(N), np.array([1, 0]))
a=mat[0]%mod
b=mat[1]%mod
print((a%mod)*(b%mod)%mod)
0