結果

問題 No.658 テトラナッチ数列 Hard
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-12 02:53:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,783 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 1,475 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 81,164 KB
最終ジャッジ日時 2023-08-28 14:50:04
合計ジャッジ時間 10,045 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,272 KB
testcase_01 AC 71 ms
71,052 KB
testcase_02 AC 83 ms
76,304 KB
testcase_03 AC 104 ms
77,492 KB
testcase_04 AC 686 ms
80,008 KB
testcase_05 AC 781 ms
79,796 KB
testcase_06 AC 968 ms
80,156 KB
testcase_07 AC 1,032 ms
79,980 KB
testcase_08 AC 1,199 ms
80,016 KB
testcase_09 AC 1,783 ms
81,008 KB
testcase_10 AC 1,781 ms
81,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 17
import sys
import io, os
input = sys.stdin.buffer.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def main():
    def mul(a, b):
        c = [[0]*len(b[0]) for i in range(len(a))]
        for i in range(len(a)):
            for k in range(len(b)):
                for j in range(len(b[0])):
                    c[i][j] = (c[i][j] + a[i][k]*b[k][j])%mod

        return c

    #A**n
    def pow(a, n):
        b = [[0]*len(a) for i in range(len(a))]
        for i in range(len(a)):
            b[i][i] = 1
        while n > 0:
            if n & 1 == 1:
                b = mul(a, b)
            a = mul(a, a)
            n = n>>1
        return b

    A = [[1, 1, 1, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]
    q = int(input())
    t1, t2, t3, t4 = 0, 0, 0, 1
    for i in range(q):
        n = int(input())
        B = pow(A, n-1)
        t = B[3][0]*t4+B[3][1]*t3+B[3][2]*t2+B[3][3]*t1
        print(t%mod)

if __name__ == '__main__':
    main()
0