题意:f[1]=a,f[2]=b,f[i]=2f[i-2]+f[i-1]+i^4(i>=3),多组询问求f[n]对2147493647取模
N,a,b < 2^31
思路:重点在于i^4的处理
对于i转移矩阵中可以记录下它的0,1,2,3,4次项
i的幂又可以由i-1的幂运算得出,最后推出的系数是二项式展开的系数
试试新的矩乘模板
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 2100000
#define MOD 2147493647
#define eps 1e-8
#define pi acos(-1)
const int MAXN=; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} struct matrix //矩阵类
{
int n,m;
ll data[MAXN][MAXN];
}; matrix ma,mb;
ll a,b,c,d,p,n; matrix matrixMul(matrix a, matrix b)
{
matrix re;
if(a.m!=b.n)
{
printf("error\n");
return re;
}
memset(re.data,,sizeof(re.data));
re.n = a.n; re.m = b.m;
for(int i = ; i <= a.n; i++)
{
for(int j = ; j <= a.m; j++)
{
if(a.data[i][j] == ) continue;
for(int k = ; k <= b.m; k++)
{
re.data[i][k] += (a.data[i][j] % MOD * b.data[j][k] % MOD) % MOD;
re.data[i][k] %= MOD;
}
}
}
return re;
} matrix matrixPow(matrix a,int b)
{
matrix re;
if(a.n!=a.m)
{
printf("error2\n");
return re;
}
re.n=re.m=a.n;
memset(re.data,,sizeof(re.data));
for(int i=;i<=re.n;i++) re.data[i][i]=;
while(b)
{
if(b&) re=matrixMul(re,a);
a=matrixMul(a,a);
b>>=;
}
return re;
} void inputMat(int n,int m,matrix &a,ll *b)
{
a.n = n; a.m = m;
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
a.data[i][j] = *(b + (i - ) * m + (j - ));
} void init(){
ll pt[][] = {b,a,,,,,};
inputMat(,,ma,*pt);
ll pt2[][] = {,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,};
inputMat(,,mb,*pt2);
} int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%I64d%I64d%I64d",&n,&a,&b);
int i=;
a%=MOD;
b%=MOD;
if(n == )
printf("%I64d\n",a);
else if(n == )
printf("%I64d\n",b);
else
{ init();
ma=matrixMul(ma,matrixPow(mb,n-));
}
printf("%I64d\n",ma.data[][]);
}
return ;
}