結果

問題 No.658 テトラナッチ数列 Hard
ユーザー merom686merom686
提出日時 2018-03-02 22:32:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 73,940 KB
実行使用メモリ 6,932 KB
最終ジャッジ日時 2023-09-03 23:15:16
合計ジャッジ時間 1,432 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,768 KB
testcase_01 AC 4 ms
6,928 KB
testcase_02 AC 4 ms
6,780 KB
testcase_03 AC 4 ms
6,712 KB
testcase_04 AC 5 ms
6,928 KB
testcase_05 AC 6 ms
6,928 KB
testcase_06 AC 6 ms
6,928 KB
testcase_07 AC 6 ms
6,932 KB
testcase_08 AC 6 ms
6,812 KB
testcase_09 AC 7 ms
6,768 KB
testcase_10 AC 6 ms
6,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int m = 1000000, k = 90000, j = 0;
    vector<int> p(m);
    p[3] = 1;
    for (int i = 4; i < m; i++) {
        p[i] = (p[i - 1] + p[i - 2] + p[i - 3] + p[i - 4]) % 17;
        if (i > k && p[i] == p[k] && p[i - 1] == p[k - 1] && p[i - 2] == p[k - 2] && p[i - 3] == p[k - 3]) {
            j = i - k;
            break;
        }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int64_t n;
        cin >> n;
        n--;

        if (n > k) {
            n = (n - k) % j + k;
        }
        cout << p[n] << '\n';
    }

    return 0;
}
0