• 斐波那契 矩阵快速幂


     1 #include <iostream>
     2 #include <cstdlib>
     3 #include <cstring>
     4 #include <queue>
     5 #include <cstdio>
     6 #include <algorithm>
     7 #include <map>
     8 #include <time.h>
     9 #include <ext/pb_ds/assoc_container.hpp>
    10 #include <ext/pb_ds/tree_policy.hpp>
    11 #define LL long long
    12 
    13 using namespace std;
    14 using namespace __gnu_pbds;
    15 
    16 const int MOD = 19999997;
    17 
    18 struct Martix
    19 {
    20     LL martix[2][2];
    21     int row,col;
    22     Martix(int _row,int _col)
    23     {
    24         memset(martix,0,sizeof(martix));
    25         row = _row;
    26         col = _col;
    27     }
    28     Martix operator *(const Martix &A)const
    29     {
    30         Martix C(row, A.col);
    31         for(int i = 0; i < row; i++)
    32             for(int j = 0; j < A.col; j++)
    33                 for(int k = 0; k < col; k++)
    34                     C.martix[i][j] =  (C.martix[i][j] + martix[i][k] * A.martix[k][j])%MOD;
    35         return C;
    36     }
    37 };
    38 
    39 
    40 void solve()
    41 {
    42     Martix A(2,2), F(2,2);
    43     A.martix[0][0] = A.martix[0][1] = A.martix[1][0] = 1;
    44     F.martix[0][0] = F.martix[1][1] = 1;
    45     int n;
    46     scanf("%d",&n);
    47     while(n > 0)
    48     {
    49         if(n & 1)
    50             F = F*A;
    51         A = A*A;
    52         n >>= 1;
    53     }
    54     printf("%lld
    ",F.martix[0][0]);
    55 }
    56 
    57 int main(void)
    58 {
    59     solve();
    60     return 0;
    61 }
  • 相关阅读:
    安装部署NetBeans mysql Tomact joget workflow 环境
    Django-分页扩展
    supervisor linux下进程管理工具
    注意python函数参数的可变变量的传递
    Python远程部署利器Fabric详解
    chrom 扩展程序安装
    supervisor
    python进度条
    os sys区别
    知乎上关于网站 权限系统的回答
  • 原文地址:https://www.cnblogs.com/henserlinda/p/5741089.html
Copyright © 2020-2023  润新知