zoukankan      html  css  js  c++  java
  • (a+b)^n

    题目::

    题解:

     1 #include<bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const ll MOD=9932017;
     5 const int maxn=1e5+5;
     6 
     7 struct mat
     8 {
     9     ll a[3][3];
    10     mat(){
    11         memset(a,0,sizeof(a));
    12     }
    13 };
    14 mat mul(mat x,mat y)
    15 {
    16     mat res;
    17     for(int i=0;i<2;i++){
    18         for(int j=0;j<2;j++){
    19             for(int k=0;k<2;k++){
    20                 res.a[i][j]=(res.a[i][j]+x.a[i][k]*y.a[k][j]%MOD)%MOD;
    21             }
    22         }
    23     }
    24     return res;
    25 }
    26 ll qpow(mat x,ll p)
    27 {
    28     mat res;
    29     res.a[0][0]=1;res.a[1][0]=1;
    30     while(p)
    31     {
    32         if(p&1){
    33             res=mul(res,x);
    34         }
    35         x=mul(x,x);
    36         p>>=1;
    37     }
    38     return (res.a[0][0]*22+res.a[0][1]*4-1)%MOD;
    39 }
    40 int main()
    41 {
    42     mat res1;
    43     res1.a[0][0]=11;res1.a[0][1]=60;
    44     res1.a[1][0]=2;res1.a[1][1]=11;
    45     int t;
    46     scanf("%d",&t);
    47     while(t--)
    48     {
    49         ll n;
    50         scanf("%lld",&n);
    51         if(n==0){
    52             printf("1");
    53         }
    54         else{
    55             printf("%lld",qpow(res1,n-1));
    56         }
    57         if(t!=0){printf("
    ");}
    58     }
    59     return 0;
    60 }
    View Code
    纵使单枪匹马,也要勇闯天涯
  • 相关阅读:
    02_虚拟机参数
    01_java虚拟机基础入门
    03_模板消息
    Redis 实现分布式锁
    01_微信小程序支付
    python产生随机字符串
    输出的编码
    jmeter MD5加密
    vscode 插件推荐
    appium自动化安装(二)
  • 原文地址:https://www.cnblogs.com/sj-gank/p/11766950.html
Copyright © 2011-2022 走看看