HDU6198 number number number

来源:互联网 发布:分类信息网群发软件 编辑:程序博客网 时间:2024/06/08 14:57
题意:
在斐波那契求k个数的和,求他们的和不能形成的最小整数。例如:0 1 1 2 3 5 8 13 21 34 55 89...求k=1不能形成的最小的整数,显然是4,k=2时,1+1=2,0+1=1,1+2=3,1+3=4,2+3=5,1+5=6,2+5=7,3+5=8,1+8=9,2+8=10,3+8=11,5+8=13,...可以看出没有12,所以k=2时的和不能形成12.发现规律是第5.7.9.11....   -1,得到0 1 1 2 4 8 12 21 33 55 88.....  因此得出规律是f(3+2*k).
由于数据太大所以用斐波那契的矩阵快速幂求。


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

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


#include <iostream>#include <cstddef>#include <cstring>#include <vector>using namespace std;typedef long long ll;const int mod=998244353;typedef vector<ll> vec;typedef vector<vec> mat;mat mul(mat &a,mat &b)//表示不会这样用,,,,{    mat c(a.size(),vec(b[0].size()));    for(int i=0; i<2; i++)    {        for(int j=0; j<2; j++)        {            for(int k=0; k<2; k++)            {                c[i][j]+=a[i][k]*b[k][j];                c[i][j]%=mod;            }        }    }    return c;}mat pow(mat a,ll n){    mat res(a.size(),vec(a.size()));    for(int i=0; i<a.size(); i++)        res[i][i]=1;//单位矩阵;    while(n)    {        if(n&1) res=mul(res,a);        a=mul(a,a);        n/=2;    }    return res;}ll solve(ll n){    mat a(2,vec(2));    a[0][0]=1;    a[0][1]=1;    a[1][0]=1;    a[1][1]=0;    a=pow(a,n);    return a[0][1]%998244353;//也可以是a[1][0];}int main(){    ll k;    while(~scanf("%lld",&k))    {        cout<<solve(3+2*k)%998244353-1<<endl;    }    return 0;}


原创粉丝点击