結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー | roaris |
提出日時 | 2020-07-25 23:58:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,321 ms / 2,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 87,080 KB |
実行使用メモリ | 81,476 KB |
最終ジャッジ日時 | 2023-09-10 02:17:37 |
合計ジャッジ時間 | 8,055 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,096 KB |
testcase_01 | AC | 73 ms
71,496 KB |
testcase_02 | AC | 86 ms
76,576 KB |
testcase_03 | AC | 117 ms
77,392 KB |
testcase_04 | AC | 563 ms
81,052 KB |
testcase_05 | AC | 631 ms
79,912 KB |
testcase_06 | AC | 765 ms
80,068 KB |
testcase_07 | AC | 809 ms
80,564 KB |
testcase_08 | AC | 918 ms
80,196 KB |
testcase_09 | AC | 1,311 ms
81,476 KB |
testcase_10 | AC | 1,321 ms
81,288 KB |
ソースコード
import sys input = sys.stdin.readline def mat_mul(A, B): C = [[0]*len(B[0]) for _ in range(len(A))] for i in range(len(A)): for j in range(len(B[0])): for k in range(len(A[0])): C[i][j] += A[i][k]*B[k][j] C[i][j] %= MOD return C def mat_pow(A, n): res = [[0]*len(A) for _ in range(len(A))] for i in range(len(A)): res[i][i] = 1 while n>0: if n&1: res = mat_mul(res, A) n >>= 1 A = mat_mul(A, A) return res Q = int(input()) MOD = 17 A = [[1, 1, 1, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]] x = [[1], [0], [0], [0]] for _ in range(Q): n = int(input()) if n<=3: print(0) else: print(mat_mul(mat_pow(A, n-4), x)[0][0])