結果
問題 |
No.658 テトラナッチ数列 Hard
|
ユーザー |
|
提出日時 | 2018-03-03 00:04:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 558 ms |
コンパイル使用メモリ | 65,924 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 00:02:47 |
合計ジャッジ時間 | 1,444 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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).space[3][3] << endl; } }