結果

問題 No.658 テトラナッチ数列 Hard
ユーザー kichirb3kichirb3
提出日時 2018-03-06 18:34:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,204 KB
実行使用メモリ 11,212 KB
最終ジャッジ日時 2023-10-20 00:05:26
合計ジャッジ時間 1,284 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,196 KB
testcase_01 AC 28 ms
10,196 KB
testcase_02 AC 38 ms
10,792 KB
testcase_03 AC 37 ms
10,796 KB
testcase_04 AC 48 ms
11,212 KB
testcase_05 AC 47 ms
11,208 KB
testcase_06 AC 47 ms
11,208 KB
testcase_07 AC 51 ms
11,208 KB
testcase_08 AC 52 ms
11,204 KB
testcase_09 AC 49 ms
11,212 KB
testcase_10 AC 50 ms
11,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.658 テトラナッチ数列 Hard
https://yukicoder.me/problems/no/658

"""
import sys
from sys import stdin
input = stdin.readline


def solve(limit):
    loop = 0
    loop_check= dict()
    res = [None, 0, 0, 0, 1]
    for i in range(5, limit+1):
        h = '{:02d}{:02d}{:02d}{:02d}'.format(res[-4], res[-3], res[-2], res[-1])
        if h in loop_check:
            loop = loop_check[h]
            break
        else:
            loop_check[h] = i
        tmp = sum(res[-4:]) % 17
        res.append(tmp)
    return res, loop


def main(args):
    Q = int(input())
    queries = [int(input()) for _ in range(Q)]

    tetra, looped = solve(max(queries))
    if looped != 0:
        loop = len(tetra) - looped
        for q in queries:
            if q % loop == 0:
                print(tetra[looped])
            elif q > loop:
                print(tetra[q % loop])
            else:
                print(tetra[q])
    else:
        for q in queries:
            print(tetra[q])


if __name__ == '__main__':
    main(sys.argv[1:])
0