結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー | ha71 |
提出日時 | 2020-10-01 11:42:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,385 bytes |
コンパイル時間 | 1,499 ms |
コンパイル使用メモリ | 165,260 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-21 06:48:09 |
合計ジャッジ時間 | 2,366 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,384 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 19 ms
4,380 KB |
testcase_05 | AC | 19 ms
4,380 KB |
testcase_06 | AC | 18 ms
4,380 KB |
testcase_07 | AC | 20 ms
4,376 KB |
testcase_08 | AC | 20 ms
4,380 KB |
testcase_09 | AC | 22 ms
4,380 KB |
testcase_10 | AC | 22 ms
4,380 KB |
ソースコード
#include <bits/stdc++.h> //#include "atcoder/all" typedef long long int ll; using namespace std; // using namespace atcoder; #define P 17 * 17 * 17 * 17 int l[P]; int first[P]; int main() { int q; cin >> q; memset(first, -1, sizeof(first)); int a1 = 0; int a2 = 0; int a3 = 0; int a4 = 1; int now = 3; int nowp = a1 * 17 * 17 * 17 + a2 * 17 * 17 + a3 * 17 + a4; int syuuki; first[nowp] = now; l[0] = 0; l[1] = 0; l[2] = 0; l[now] = nowp; while (true) { int temp = (a1 + a2 + a3 + a4) % 17; a1 = a2; a2 = a3; a3 = a4; a4 = temp; now++; nowp = a1 * 17 * 17 * 17 + a2 * 17 * 17 + a3 * 17 + a4; if (first[nowp] == -1) { first[nowp] = now; l[now] = nowp; } else { // cout << now << endl; syuuki = now - first[nowp]; break; } } int kijun = first[nowp]; // cout << kijun << endl; // for (int i = 0; i < 50; i++) { // cout << l[i] << endl; // } for (int i = 0; i < q; i++) { ll n; cin >> n; n--; //l[(n - kijun) % syuuki + kijun] if (n >= kijun) { cout << l[(n - kijun) % syuuki + kijun] % 17 << endl; } else { cout << l[n] % 17 << endl; } } return 0; }