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\n",query(n));
71     }
72     return 0;
73 }

 

posted on 2017-09-11 15:29  hhhhx  阅读(143)  评论(0编辑  收藏  举报

导航