結果
| 問題 |
No.658 テトラナッチ数列 Hard
|
| コンテスト | |
| ユーザー |
T1610
|
| 提出日時 | 2018-04-28 18:03:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 221 ms / 2,000 ms |
| コード長 | 1,762 bytes |
| コンパイル時間 | 1,526 ms |
| コンパイル使用メモリ | 168,408 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 23:22:50 |
| 合計ジャッジ時間 | 3,390 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 17;
double EPS = 1e-8;
template <int SZ>
struct Mat {
array<array<ll, SZ>, SZ> d;
const int n;
Mat() : n(SZ) {
array<ll, SZ> tmp;
tmp.fill(0);
d.fill(tmp);
}
Mat<SZ> operator * (const Mat<SZ>& mt) const {
Mat<SZ> ret;
rep(i, SZ) rep(j, SZ) {
ll sum = 0LL;
rep(k, SZ) {
(ret.d[i][j] += (d[i][k] * mt.d[k][j]) % MOD) %= MOD;
}
}
return ret;
}
Mat<SZ>& operator = (const Mat<SZ>& mt) {
d = mt.d;
return *this;
}
};
template <int SZ>
Mat<SZ> pow(Mat<SZ> mt, ll n) {
Mat<SZ> ret;
rep(i, SZ) ret.d[i][i] = 1LL;
while(n > 0) {
if(n&1LL) ret = ret * mt;
mt = mt*mt;
n >>= 1;
}
return ret;
}
int main() {
int q;
cin >> q;
Mat<4> mt;
rep(i, 4) mt.d[0][i] = 1;
rep(i, 3) mt.d[i+1][i] = 1;
rep(i, q) {
ll n;
cin >> n;
auto tmp = pow(mt, n);
// cout << "n : " << tmp.n << endl;
// rep(i, tmp.n) {
// rep(j, tmp.n) {
// cout << " " << tmp.d[i][j];
// }
// cout << endl;
// }
cout << tmp.d[3][3] << endl;
}
return 0;
}
T1610