原题链接

考察:矩阵快速幂

思路:

        矩阵快速幂的入门题,记住模板.

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <cstdio>
 5 using namespace std;
 6 typedef long long LL;
 7 const int Mod = 10000;
 8 int n;
 9 void mul(int f[],int c[][2])
10 {
11     int res[2];
12     memset(res,0,sizeof res);
13     for(int i=0;i<2;i++)
14       for(int j=0;j<2;j++)
15         res[i] = (res[i]+(LL)f[j]*c[j][i])%Mod;
16     memcpy(f,res,sizeof res);
17 }
18 void mulself(int a[][2])
19 {
20     int res[2][2];
21     memset(res,0,sizeof res);
22     for(int i=0;i<2;i++)
23       for(int j=0;j<2;j++)
24         for(int k=0;k<2;k++)
25           res[i][j] = (res[i][j]+(LL)a[i][k]*a[k][j])%Mod;
26     memcpy(a,res,sizeof res);
27 }
28 int main() 
29 {
30     while(scanf("%d",&n)!=EOF&&n!=-1)
31     {
32         int a[2][2] = {{1,1},{1,0}},f[2] = {1,0};
33         while(n)
34         {
35             if(n&1) mul(f,a);
36             mulself(a);
37             n>>=1;
38         }
39         printf("%d\n",f[1]);
40     }
41     return 0;
42 }