結果

問題 No.658 テトラナッチ数列 Hard
ユーザー kurimupy
提出日時 2020-06-15 23:26:55
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 745 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,624 KB
最終ジャッジ日時 2024-07-03 11:39:37
合計ジャッジ時間 15,766 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

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