結果

問題 No.657 テトラナッチ数列 Easy
ユーザー ミドリムシ
提出日時 2018-03-05 16:44:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 70,496 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-07-22 10:23:48
合計ジャッジ時間 2,285 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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