就是来存个板子……
struct matrix
{
int x,y,num[35][35];
matrix() : x(0),y(0) {memset(num,0,sizeof(num));}
matrix operator*(matrix b)
{
matrix c;
c.x=x,c.y=b.y;
for(int k=1;k<=y;++k)
for(int i=1;i<=x;++i)
for(int j=1;j<=b.y;++j)
c.num[i][j]=(c.num[i][j]+num[i][k]*b.num[k][j]%m)%m;
return c;
}
matrix operator+(matrix b)
{
matrix c;
c.x=x,c.y=y;
for(int i=1;i<=x;++i)
for(int j=1;j<=y;++j)
c.num[i][j]=(num[i][j]+b.num[i][j])%m;
return c;
}
}a;
matrix qpow(matrix a,int p)
{
matrix res;
res.x=a.x,res.y=a.y;
for(int i=1;i<=res.x;++i) res.num[i][i]=1;
for(;p;p>>=1)
{
if(p&1) res=res*a;
a=a*a;
}
return res;
}