結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー |
|
提出日時 | 2018-03-02 23:57:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,054 bytes |
コンパイル時間 | 556 ms |
コンパイル使用メモリ | 65,280 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-22 23:20:13 |
合計ジャッジ時間 | 1,406 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 |
ソースコード
#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 - 1).space[3][0] << endl;}}