結果

問題 No.658 テトラナッチ数列 Hard
ユーザー 👑 KazunKazun
提出日時 2020-08-08 02:15:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,085 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,556 KB
実行使用メモリ 78,364 KB
最終ジャッジ日時 2023-10-25 09:31:50
合計ジャッジ時間 6,471 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,428 KB
testcase_01 AC 48 ms
61,748 KB
testcase_02 AC 55 ms
64,016 KB
testcase_03 AC 94 ms
76,264 KB
testcase_04 AC 497 ms
78,364 KB
testcase_05 AC 546 ms
78,036 KB
testcase_06 AC 655 ms
78,112 KB
testcase_07 AC 680 ms
78,096 KB
testcase_08 AC 773 ms
78,220 KB
testcase_09 AC 1,085 ms
78,328 KB
testcase_10 AC 1,082 ms
78,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
#===========================================
def m(A,B):
    C=[[0]*4 for i in range(4)]
    for i in range(4):
        for j in range(4):
            X=0
            for k in range(4):
                X+=A[i][k]*B[k][j]
                X%=17
            C[i][j]=X
    return C
#===========================================
Q=int(input())
X=[0]*Q

M=[[1,1,1,1],[1,0,0,0],[0,1,0,0],[0,0,1,0]]


for i in range(Q):
    N=int(input())
    A=[[1*(i==j) for i in range(4)] for j in range(4)]
    B=deepcopy(M)

    while N>0:
        if N%2:
            A=m(A,B)
        N>>=1
        B=m(B,B)
    X[i]=A[-1][-1]
print("\n".join(map(str,X)))
0