#include <string.h> const int mod=1e9+7; struct MM { int r,c; int mx[105][105]; MM(int rr=0,int cc=0){r=rr,c=cc;} friend MM operator *(MM ta,MM tb) { MM tc(ta.r,tb.c); for(int i=1;i<=tc.r;i++) for(int j=1;j<=tc.c;j++) { tc.mx[i][j]=0; for(int k=1;k<=tb.r;k++) tc.mx[i][j]=(tc.mx[i][j]+ta.mx[i][k]*tb.mx[k][j])%mod; } return tc; } friend MM operator ^(MM ta,int num) { MM ret(ta.r,ta.c); //r==c memset(ret.mx,0,sizeof ret.mx); for(int i=1;i<=ta.r;i++) ret.mx[i][i]=1; //单位矩阵 while(num) { if(num&1) ret=ta*ret; num>>=1; ta=ta*ta; } return ret; } };