結果

問題 No.658 テトラナッチ数列 Hard
ユーザー kurimupykurimupy
提出日時 2020-06-15 23:26:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 745 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 30,436 KB
最終ジャッジ日時 2023-09-16 10:40:49
合計ジャッジ時間 13,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
29,556 KB
testcase_01 AC 126 ms
29,560 KB
testcase_02 AC 123 ms
29,504 KB
testcase_03 AC 130 ms
29,532 KB
testcase_04 AC 940 ms
30,116 KB
testcase_05 AC 1,106 ms
30,276 KB
testcase_06 AC 1,405 ms
30,164 KB
testcase_07 AC 1,520 ms
30,156 KB
testcase_08 AC 1,815 ms
30,080 KB
testcase_09 TLE -
testcase_10 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#Fibonacchi sequence
import numpy as np
import sys
input = sys.stdin.readline
A=np.array([[1, 1, 1, 1], [1, 0, 0, 0], [
        0, 1, 0, 0], [0, 0, 1, 0]])
mod = 17
def mat_f(X):
    if X == 0:
        return np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
    elif X == 1:
        return A
    else:
        if X % 2 == 0:
            S = mat_f(X//2)
            return np.dot(S, S) % mod
        else:
            S = mat_f(X//2)
            return np.dot(np.dot(S, S), A) % mod


def main():
    Q = int(input())
    d = [int(input()) for i in range(Q)]
    for i in range(Q):
        K = np.dot(mat_f(d[i]-1), np.array([1, 0, 0, 0]))
        ans = (K[-1]) % mod
        print(ans)


if __name__ == "__main__":
    main()

0