結果

問題 No.657 テトラナッチ数列 Easy
ユーザー ミドリムシミドリムシ
提出日時 2018-03-05 16:44:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 2,063 ms
コンパイル使用メモリ 69,124 KB
実行使用メモリ 34,752 KB
最終ジャッジ日時 2023-09-29 16:18:04
合計ジャッジ時間 3,716 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
34,684 KB
testcase_01 AC 51 ms
34,480 KB
testcase_02 AC 50 ms
34,524 KB
testcase_03 AC 50 ms
34,520 KB
testcase_04 AC 51 ms
34,624 KB
testcase_05 AC 65 ms
34,648 KB
testcase_06 AC 51 ms
34,516 KB
testcase_07 AC 50 ms
34,528 KB
testcase_08 AC 50 ms
34,516 KB
testcase_09 AC 66 ms
34,488 KB
testcase_10 AC 67 ms
34,580 KB
testcase_11 AC 66 ms
34,572 KB
testcase_12 AC 67 ms
34,516 KB
testcase_13 AC 68 ms
34,752 KB
testcase_14 AC 68 ms
34,644 KB
testcase_15 AC 68 ms
34,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct matrix_array{
    int array[4];
    
    matrix_array operator *(matrix_array another){
        matrix_array ans;
        for(int i = 0; i < 3; i++){
            ans.array[i] = (array[0] * another.array[i + 1] + array[i + 1] * another.array[0]) % 17;
        }
        ans.array[3] = array[0] * another.array[0] % 17;
        for(int i = 1; i < 4; i++){
            ans.array[3] += array[0] * another.array[i] + array[i] * another.array[0];
            ans.array[3] %= 17;
        }
        return ans;
    }
};

const matrix_array A = {{1, 0, 0, 0}};
const matrix_array E = {{0, 0, 0, 1}};

int main(){
    int Q;
    cin >> Q;
    matrix_array matrixes[int(2e6)];
    matrixes[0] = {{0, 0, 0, 1}};
    for(int i = 1; i < 2e6; i++){
        matrixes[i] = matrixes[i - 1] * A;
    }
    for(int i = 0; i < Q; i++){
        int n;
        cin >> n;
        cout << matrixes[n - 1].array[0] << endl;
    }
}
0