結果

問題 No.657 テトラナッチ数列 Easy
ユーザー realDivineJKrealDivineJK
提出日時 2020-05-27 20:38:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 697 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 79,080 KB
最終ジャッジ日時 2024-04-21 05:17:33
合計ジャッジ時間 6,038 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,096 KB
testcase_01 AC 37 ms
52,480 KB
testcase_02 AC 38 ms
52,352 KB
testcase_03 AC 39 ms
52,096 KB
testcase_04 AC 47 ms
60,288 KB
testcase_05 AC 130 ms
76,928 KB
testcase_06 AC 39 ms
52,096 KB
testcase_07 AC 39 ms
52,352 KB
testcase_08 AC 54 ms
62,976 KB
testcase_09 AC 532 ms
78,296 KB
testcase_10 AC 527 ms
78,376 KB
testcase_11 AC 526 ms
78,200 KB
testcase_12 AC 605 ms
78,576 KB
testcase_13 AC 697 ms
79,080 KB
testcase_14 AC 689 ms
78,068 KB
testcase_15 AC 691 ms
78,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q = int(input())
mod = 17
def matprod(m1, m2, n, l, m):
    y = [[0 for _ in range(m)] for __ in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(l):
                y[i][j] += m1[i][k] * m2[k][j] % mod
                y[i][j] %= mod
    return y
    
def matpow(m1, n, m):
    y = [[i==j for j in range(n)] for i in range(n)]
    bas = [[m1[i][j] for j in range(n)] for i in range(n)]
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y = matprod(y, bas, n, n, n)[:][:]
        bas = matprod(bas, bas, n, n, n)[:][:]
        tmp //= 2
    return y
vec = [0, 0, 0, 1]
for _ in range(Q):
    n = int(input())
    M = [
        [0, 1, 0, 0],
        [0, 0, 1, 0],
        [0, 0, 0, 1],
        [1, 1, 1, 1]
        ]
    m = matpow(M, 4, n-1)
    S = 0
    for i in range(4):
        S += m[0][i] * vec[i] % mod
        S %= mod
    print(S)
0