unsigned int 0~4294967295
int -2147483648~2147483647
unsigned long 0~4294967295
long -2147483648~2147483647
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:1844674407370955161
__int64的最大值:9223372036854775807
__int64的最小值:-9223372036854775808
unsigned __int64的最大值:18446744073709551615
矩阵快速幂和快速幂完全类似。
(1,2,1,4,6,4,1,
1,0,0,0,0,0,0,
0,0,1,4,6,4,1,
0,0,0,1,3,3,1,
0,0,0,0,1,2,1,
0,0,0,0,0,1,1,
0,0,0,0,0,0,1)这样的矩阵乘上(f(i - 1) ,f(i - 2) , (i - 1) ^ 4,(i - 1) ^ 3, (i - 1) ^ 2,(i - 1),1)
i^4=(i - 1) ^ 4 + 4 * (i - 1) ^ 3 + 6 * (i - 1) ^ 2 + 4 * (i - 1) + 1;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL MAXN = 2147493647;
//注意这里有大坑,我原先这里写的是int类型,我还以为给的模数正好不会超int,原来int的范围
是2147483647,他给的是2147493647,看到非常神似,其实比int大。。。。
typedef struct node{
LL arr[7][7];
}node;
node mul(node n,node m)
{
node x;
int i,j,k;
for(i = 0;i < 7;++i)
{
for(j = 0;j < 7;++j)
{
x.arr[i][j] = 0;
for(k = 0;k < 7;++k)
{
x.arr[i][j] = (x.arr[i][j] + (n.arr[i][k] % MAXN * m.arr[k][j] % MAXN) % MAXN) % MAXN;
}
}
}
return x;
}
node Pow_mod(node n,LL m)
{
node ans;
int i,j;
for(i = 0;i < 7;++i)
{
for(j = 0;j < 7;++j)
{
if(j == i)
ans.arr[i][j] = 1;
else{
ans.arr[i][j] = 0;
}
}
}
while(m)
{
if(m & 1)
ans = mul(ans,n);
n = mul(n,n);
m >>= 1;
}
return ans;
}
int main()
{
int t;
cin>>t;
node mat = {1,2,1,4,6,4,1,
1,0,0,0,0,0,0,
0,0,1,4,6,4,1,
0,0,0,1,3,3,1,
0,0,0,0,1,2,1,
0,0,0,0,0,1,1,
0,0,0,0,0,0,1
};
/*int i,j;
for(i = 0;i < 7;++i)
{
for(j = 0;j < 7;++j)
{
cout<<mat.arr[i][j]<<" ";
}
cout<<endl;
}*/
while(t--)
{
LL n,a,b;
scanf("%lld %lld %lld",&n,&a,&b);
int i,j;
node ans = {b,0,0,0,0,0,0,a,0,0,0,0,0,0,16,0,0,0,0,0,0,8,0,0,0,0,0,0,4,0,0,0,0,0,0,2,0,0,0,0,0,0,1,0,0,0,0,0,0};
if(n == 1) printf("%lld\n",a % MAXN);
else{
if(n == 2)
printf("%lld\n",b % MAXN);
else{
node m = Pow_mod(mat,n - 2);
/*for(i = 0;i < 7;++i)
{
for(j = 0;j < 7;++j)
{
cout<<ans.arr[i][j]<<" ";
}
cout<<endl;
}*/
node sum = mul(m,ans);
printf("%lld\n",sum.arr[0][0] % MAXN);
}
}
}
return 0;
}