結果

問題 No.658 テトラナッチ数列 Hard
ユーザー ミドリムシミドリムシ
提出日時 2018-03-03 00:04:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,050 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 66,604 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-05 03:13:36
合計ジャッジ時間 1,620 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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