https://blog.csdn.net/NYIST_TC_LYQ/article/details/52981353
注意原文章是求了n次幂,所以第一项为第n+1位的斐波那契,第二项才是第n位。
const int MOD=10000;
struct mat
{
long long a[2][2];
};
mat mat_mul(mat x,mat y)
{
mat res;
memset(res.a,0,sizeof(res.a));
for(int i=0; i<2; i++)
{
for(int j=0; j<2; j++)
{
for(int k=0; k<2; k++)
{
res.a[i][j]=(res.a[i][j]+x.a[i][k]*y.a[k][j])%MOD;
}
}
}
return res;
}
void mat_pow(int n)
{
mat c,res;
c.a[0][0]=c.a[0][1]=c.a[1][0]=1;
c.a[1][1]=0;
memset(res.a,0,sizeof(res.a));
for(int i=0; i<2; i++)
res.a[i][i]=1;
while(n)
{
if(n&1)
{
res=mat_mul(res,c);
}
c=mat_mul(c,c);
n=n>>1;
}
printf("%lld\n",res.a[0][1]);
}