結果

問題 No.658 テトラナッチ数列 Hard
ユーザー kurimupykurimupy
提出日時 2020-06-15 23:21:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 682 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 30,336 KB
最終ジャッジ日時 2023-09-16 10:38:29
合計ジャッジ時間 14,282 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
29,640 KB
testcase_01 AC 126 ms
29,520 KB
testcase_02 AC 128 ms
29,436 KB
testcase_03 AC 135 ms
29,592 KB
testcase_04 AC 973 ms
30,248 KB
testcase_05 AC 1,153 ms
30,224 KB
testcase_06 AC 1,406 ms
30,152 KB
testcase_07 AC 1,519 ms
30,052 KB
testcase_08 AC 1,838 ms
30,336 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]], dtype="int64")

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)
            S %= mod
            return np.dot(S, S)
        else:
            S = mat_f(X//2)
            S %= mod
            return np.dot(np.dot(S, S), A)


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