HDU6198 number number number

来源:互联网 发布:mac safari总是崩溃 编辑:程序博客网 时间:2024/05/18 09:02

number number number

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


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
2017 ACM/ICPC Asia Regional Shenyang Online

——————————————————————————————————
题目的意思是在斐波那契序列中找出k个数从凑出的数是good的,不能就是bad的,给出k,求最小的bad数
思路:找规律发现这个数是斐波那契第2*k+3项-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 longconst 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;}



原创粉丝点击