結果

問題 No.658 テトラナッチ数列 Hard
コンテスト
ユーザー ミドリムシ
提出日時 2018-03-03 00:04:22
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,050 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 315 ms
コンパイル使用メモリ 78,436 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-07 07:52:34
合計ジャッジ時間 1,333 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
using namespace std;

struct matrix{
    int space[4][4];
    
    matrix operator *(const matrix &another) const{
        matrix ans;
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                ans.space[i][j] = 0;
                for(int k = 0; k < 4; k++){
                    ans.space[i][j] += space[i][k] * another.space[k][j];
                }
                ans.space[i][j] %= 17;
            }
        }
        return ans;
    }
};

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

matrix power(long exponent){
    if(exponent % 2){
        return power(exponent - 1) * A;
    }else if(exponent){
        matrix root_ans = power(exponent / 2);
        return root_ans * root_ans;
    }else{
        return E;
    }
}

int main(){
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        long num;
        cin >> num;
        cout << power(num).space[0][0] << endl;
    }
}
0