zoukankan      html  css  js  c++  java
  • hud 6198 number number number

    题意:斐波那契数列f,现在给出k,问3个不同的f[i]之和,不能组成的最小数是什么

    思路:模拟发现。。。。a[n]=f((n+1)*2+1)-1;矩阵快速幂

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const LL MOD=998244353;
     5 struct Matrix
     6 {
     7     LL a[4][4];
     8     Matrix()
     9     {
    10         memset(a,0,sizeof(a));
    11     }
    12     void init()
    13     {
    14         for(int i=0;i<4;i++)
    15             for(int j=0;j<4;j++)
    16                 a[i][j]=(i==j);
    17     }
    18     Matrix operator + (const Matrix &B)const
    19     {
    20         Matrix C;
    21         for(int i=0;i<4;i++)
    22             for(int j=0;j<4;j++)
    23                 C.a[i][j]=(a[i][j]+B.a[i][j])%MOD;
    24         return C;
    25     }
    26     Matrix operator * (const Matrix &B)const
    27     {
    28         Matrix C;
    29         for(int i=0;i<4;i++)
    30             for(int k=0;k<4;k++)
    31                 for(int j=0;j<4;j++)
    32                     C.a[i][j]=(C.a[i][j]+1LL*a[i][k]*B.a[k][j])%MOD;
    33         return C;
    34     }
    35     Matrix operator ^ (const LL &t)const
    36     {
    37         Matrix A=(*this),res;
    38         res.init();
    39         LL p=t;
    40         while(p)
    41         {
    42             if(p&1)res=res*A;
    43             A=A*A;
    44             p>>=1;
    45         }
    46         return res;
    47     }
    48 };
    49 Matrix base;
    50 void init()
    51 {
    52 
    53        base.a[0][0]=0;base.a[0][1]=1;
    54        base.a[1][0]=1;base.a[1][1]=1;
    55 }
    56 LL query(LL x)
    57 {
    58     x++;
    59     x=x*2+1;
    60     x-=2;
    61     Matrix ans=base^(x);
    62     return (ans.a[0][1]+ans.a[1][1]-1+MOD)%MOD;
    63 }
    64 int main()
    65 {
    66     init();
    67     LL n;
    68     while(~scanf("%lld",&n))
    69     {
    70         printf("%lld
    ",query(n));
    71     }
    72     return 0;
    73 }
  • 相关阅读:
    Java IO总结
    Tomcat处理一个HTTP请求的过程
    Tomcat的web项目部署方式
    Tomcat性能调优
    jquery基础知识汇总
    Javascript中的正则表达式
    HTTP首部
    HTTPS
    Javascript中关于cookie的那些事儿
    HTTP请求方法详解
  • 原文地址:https://www.cnblogs.com/hhxj/p/7505214.html
Copyright © 2011-2022 走看看