結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー | alexara1123 |
提出日時 | 2019-09-21 15:14:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,876 ms / 2,000 ms |
コード長 | 717 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 81,592 KB |
実行使用メモリ | 78,116 KB |
最終ジャッジ日時 | 2023-10-19 03:09:54 |
合計ジャッジ時間 | 9,922 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,444 KB |
testcase_01 | AC | 44 ms
59,680 KB |
testcase_02 | AC | 52 ms
64,120 KB |
testcase_03 | AC | 82 ms
75,892 KB |
testcase_04 | AC | 742 ms
77,248 KB |
testcase_05 | AC | 828 ms
77,248 KB |
testcase_06 | AC | 1,026 ms
77,404 KB |
testcase_07 | AC | 1,102 ms
77,440 KB |
testcase_08 | AC | 1,307 ms
77,556 KB |
testcase_09 | AC | 1,876 ms
78,116 KB |
testcase_10 | AC | 1,868 ms
78,116 KB |
ソースコード
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]) % 17 return c 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 def main(): q = int(input()) a = [[1, 1, 1, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]] for i in range(q): n = int(input()) an = pow(a, n) print(an[3][3]) if __name__ == '__main__': main()