You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
898 B
43 lines
898 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define int long long
|
|
#define endl "\n"
|
|
const int MOD = 1e9 + 7;
|
|
const int N = 4;
|
|
int n;
|
|
|
|
// 矩阵乘法
|
|
void mul(int a[][N], int b[][N], int c[][N]) {
|
|
int t[N][N] = {0};
|
|
for (int i = 0; i < N; i++)
|
|
for (int j = 0; j < N; j++)
|
|
for (int k = 0; k < N; k++)
|
|
t[i][j] = (t[i][j] + (a[i][k] * b[k][j] % MOD)) % MOD;
|
|
memcpy(c, t, sizeof t);
|
|
}
|
|
|
|
void solve() {
|
|
int b[N][N] = {1, 1, 1}, m[N][N] = {0};
|
|
m[0][2] = m[1][0] = m[2][1] = m[2][2] = 1;
|
|
|
|
for (int i = n - 3; i; i >>= 1) {
|
|
if (i & 1) mul(b, m, b);
|
|
mul(m, m, m);
|
|
}
|
|
|
|
printf("%lld\n", b[0][2]);
|
|
}
|
|
|
|
signed main() {
|
|
int T;
|
|
cin >> T;
|
|
while (T--) {
|
|
cin >> n;
|
|
if (n <= 3) {
|
|
printf("1\n");
|
|
continue;
|
|
}
|
|
solve();
|
|
}
|
|
}
|