結果
| 問題 |
No.658 テトラナッチ数列 Hard
|
| コンテスト | |
| ユーザー |
brthyyjp
|
| 提出日時 | 2020-09-12 02:53:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,949 ms / 2,000 ms |
| コード長 | 985 bytes |
| コンパイル時間 | 418 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 79,360 KB |
| 最終ジャッジ日時 | 2024-12-29 16:45:08 |
| 合計ジャッジ時間 | 10,833 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
ソースコード
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()
brthyyjp