#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
struct matrix{
long long arr[2][2];
};
matrix base,ans;
matrix matrix_multip(matrix a,matrix b){
matrix tmp;
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
tmp.arr[i][j] = 0;
for(int k=0; k<2; k++)
tmp.arr[i][j] = (tmp.arr[i][j]+a.arr[i][k]*b.arr[k][j])%1000000009;
}
}
return tmp;
}
void matrix_pow(matrix a,long long n){
while(n){
if(n%2)
ans = matrix_multip(ans,a);
a = matrix_multip(a,a);
n /= 2;
}
}
int main(){
base.arr[0][0] = base.arr[0][1] = base.arr[1][0] = 1;
base.arr[1][1] = 0;
long long n;
scanf("%lld",&n) ;
ans.arr[0][0] = ans.arr[1][1] = 1;
ans.arr[0][1] = ans.arr[1][0] = 0;
matrix_pow(base,n);
printf("%lld\n",ans.arr[0][1]);
return 0;
}
矩阵快速幂1242斐波那契数列的第N项
最新推荐文章于 2020-10-06 12:42:35 发布