HDU6198-number number number

number number number

                                                                    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                                                              Total Submission(s): 619    Accepted Submission(s): 395


Problem Description
We define a sequence  F :

  F0=0,F1=1 ;
  Fn=Fn1+Fn2 (n2) .

Give you an integer  k , if a positive number  n  can be expressed by
n=Fa1+Fa2+...+Fak  where  0a1a2ak , this positive number is  mjfgood . Otherwise, this positive number is  mjfbad .
Now, give you an integer  k , you task is to find the minimal positive  mjfbad  number.
The answer may be too large. Please print the answer modulo 998244353.
 

Input
There are about 500 test cases, end up with EOF.
Each test case includes an integer  k  which is described above. ( 1k109 )
 

Output
For each case, output the minimal  mjfbad  number mod 998244353.
 

Sample Input
  
  
1
 

Sample Output
  
  
4
 

Source
 


题意:给你一个斐波那契数列,问用其中k个数字最小的组不成的数字是几

解题思路:多写几个后可以发现规律,斐波那契数列为0 1 1 2 3 5 8 13 21 34 55 89...k=1时答案是4,k=2时答案是12,k=3时答案是33,所以答案是第5.7.9.11....项-1


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;
const LL mod=998244353;

struct Matrix
{
    LL v[5][5];
    Matrix()
    {
        memset(v,0,sizeof v);
    }
} dan;

Matrix mul(Matrix a,Matrix b,int d)
{
    Matrix ans;
    for(int i=0; i<d; i++)
    {
        for(int j=0; j<d; j++)
        {
            for(int k=0; k<d; k++)
            {
                ans.v[i][j]+=(a.v[i][k]*b.v[k][j])%mod;
                ans.v[i][j]%=mod;
            }
        }
    }
    return ans;
}

Matrix pow(Matrix a,int k,int d)
{
    Matrix ans=dan;
    while(k)
    {
        if(k&1) ans=mul(ans,a,d);
        k>>=1;
        a=mul(a,a,d);
    }
    return ans;
}

int main()
{
    int k;
    while(~scanf("%d",&k))
    {
        dan.v[0][0]=1,dan.v[0][1]=0;
        Matrix a;
        a.v[0][0]=a.v[0][1]=a.v[1][0]=1,a.v[1][1]=0;
        Matrix ans= pow(a,2*k+2,2);
        printf("%lld\n",((ans.v[0][0]-1)%mod+mod)%mod);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值