焦作网络赛L-Poor God Water【矩阵快速幂】

时间:2023-03-09 07:09:57
焦作网络赛L-Poor God Water【矩阵快速幂】

God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous.

Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 33 continuous hours when he eats only one kind of food, he will be unhappy. Besides, if there are 33 continuous hours when he eats all kinds of those, with chocolate at the middle hour, it will be dangerous. Moreover, if there are 33 continuous hours when he eats meat or fish at the middle hour, with chocolate at other two hours, it will also be dangerous.

Now, you are the doctor. Can you find out how many different kinds of diet that can make God Water happy and safe during NN hours? Two kinds of diet are considered the same if they share the same kind of food at the same hour. The answer may be very large, so you only need to give out the answer module 10000000071000000007.

Input

The fist line puts an integer TT that shows the number of test cases. (T \le 1000T≤1000)

Each of the next TT lines contains an integer NN that shows the number of hours. (1 \le N \le 10^{10}1≤N≤1010)

Output

For each test case, output a single line containing the answer.

样例输入复制

3
3
4
15

样例输出复制

20
46
435170

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

就是告诉你任意三个可以填的情况 推n个的时候有多少种情况

像这种前一种情况可以推后一种情况的 而且n还这么大的 可以考虑矩阵快速幂

建一个9*9的矩阵 每一种表示一个2位可填的状态 行表示前两个 列表示这前两个可推出的后两个

比如MCC是一种可行的 就在MC这行对应CC这列写1

快速幂可得所有情况

 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<set>
#include<stack>
//#include<bits/stdc++.h>
#define inf 0x7f7f7f7f7f7f7f7f
using namespace std;
typedef long long LL; const LL mod = 1e9 + ;
int t;
LL n; struct Matrix {
LL a[][] = {{}};
Matrix operator * (const Matrix &b)const {
Matrix ret;
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
ret.a[i][j] = ;
for (int k = ; k <= ; k++) {
ret.a[i][j] += a[i][k] * b.a[k][j];
ret.a[i][j] %= mod;
}
}
}
return ret;
}
}; Matrix ksm(Matrix a, LL x)
{
Matrix ret, k;
k = a;
ret = a;
x--;
while (x) {
if (x & ) {
ret = ret * k;
}
x >>= ;
k = k * k;
}
return ret;
} int main()
{
cin >> t;
while (t--) {
cin >> n;
if (n == ) {
cout << << endl;
}
else if (n == ) {
cout << << endl;
}
else {
Matrix m;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = m.a[][] = ;
m = ksm(m, n - );
LL f[] = { , , , , , , , , , };
LL ans[] = { };
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
ans[i] += m.a[i][j] * f[j];
ans[i] %= mod;
}
} LL res = ;
for (int i = ; i <= ; i++) {
res = (res + ans[i]) % mod;
}
cout << res << endl;
}
}
return ;
}