結果
問題 |
No.658 テトラナッチ数列 Hard
|
ユーザー |
|
提出日時 | 2018-03-02 23:56:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 63 ms / 2,000 ms |
コード長 | 1,316 bytes |
コンパイル時間 | 606 ms |
コンパイル使用メモリ | 70,656 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-22 23:17:45 |
合計ジャッジ時間 | 1,464 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> 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; } void output(){ for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ cout << space[i][j] << " "; } cout << endl; } cout << endl; } }; 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; } }