結果

問題 No.658 テトラナッチ数列 Hard
ユーザー kurimupykurimupy
提出日時 2020-06-15 23:23:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 628 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 30,508 KB
最終ジャッジ日時 2023-09-16 10:39:00
合計ジャッジ時間 13,528 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,312 KB
testcase_01 AC 126 ms
29,360 KB
testcase_02 AC 129 ms
29,508 KB
testcase_03 AC 132 ms
29,508 KB
testcase_04 AC 971 ms
30,104 KB
testcase_05 AC 1,131 ms
30,100 KB
testcase_06 AC 1,445 ms
30,204 KB
testcase_07 AC 1,498 ms
30,260 KB
testcase_08 AC 1,797 ms
30,216 KB
testcase_09 TLE -
testcase_10 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#Fibonacchi sequence
import numpy as np

A = np.array([[1, 1, 1, 1], [1, 0, 0, 0], [
             0, 1, 0, 0], [0, 0, 1, 0]])

mod = 17


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


Q = int(input())
d = [int(input()) for i in range(Q)]
for i in range(Q):
    K=np.dot(mat_f(d[i]-1),np.array([1,0,0,0]))
    ans=(K[-1])%mod
    print(ans)

0