输入1个数n(1 <= n <= 10^18)。
输出F(n) % 1000000009的结果。
11
89
1 #include <cstdio> 2 3 const int mod(1000000009); 4 #define LL long long 5 inline void read(LL &x) 6 { 7 x=0; register char ch=getchar(); 8 for(; ch>‘9‘||ch<‘0‘; ) ch=getchar(); 9 for(; ch>=‘0‘&&ch<=‘9‘; ch=getchar()) x=x*10+ch-‘0‘; 10 } 11 LL n; 12 13 struct Matrix { 14 LL e[2][2]; 15 Matrix operator * (const Matrix x) const 16 { 17 Matrix tmp; 18 for(int i=0; i<2; ++i) 19 for(int j=0; j<2; ++j) 20 { 21 tmp.e[i][j]=0; 22 for(int k=0; k<2; ++k) 23 tmp.e[i][j]+=e[i][k]*x.e[k][j],tmp.e[i][j]%=mod; 24 } 25 return tmp; 26 } 27 }ans,base; 28 29 int Presist() 30 { 31 read(n); 32 ans.e[0][0]=ans.e[1][1]=1; 33 base.e[0][0]=base.e[0][1]=base.e[1][0]=1; 34 for(; n; n>>=1, base=base*base) 35 if(n&1) ans=ans*base; 36 printf("%lld",ans.e[0][1]); 37 return 0; 38 } 39 40 int Aptal=Presist(); 41 int main(){;}
原文:http://www.cnblogs.com/Shy-key/p/7529929.html