結果

問題 No.658 テトラナッチ数列 Hard
ユーザー kurimupykurimupy
提出日時 2020-06-15 23:25:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 756 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 30,180 KB
最終ジャッジ日時 2023-09-16 10:38:32
合計ジャッジ時間 2,387 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#Fibonacchi sequence
import numpy as np
import sys
input = sys.stdin.readline


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():
    A = np.array([[1, 1, 1, 1], [1, 0, 0, 0], [
        0, 1, 0, 0], [0, 0, 1, 0]])
    mod = 17
    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