2017 icpc 沈阳赛区 1005.number number number(矩阵快速幂)



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

 【AC代码】

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))

const int inf=0x3f3f3f3f;
const ll mod=998244353;
ll ans[3][3],p[3][3];
ll m,q;

void multi(ll a[][3],ll b[][3])
{
    ll tmp[3][3];
    mem(tmp,0);
    for1(i,2)
        for1(j,2)
            for1(k,2)
                tmp[i][j]=(tmp[i][j]+a[i][k]*b[k][j])%mod;
    for1(i,2)
        for1(j,2)
            a[i][j]=tmp[i][j];
}

void init()
{
    mem(ans,0);
    ans[1][1]=ans[2][2]=1;
    p[1][1]=p[1][2]=p[2][1]=1,p[2][2]=0;
}

void quick(ll x)
{
    while(x)
    {
        if(x&1)multi(ans,p);
        multi(p,p);
        x>>=1;
    }
}

int main()
{
    while(~sf("%lld",&m))
    {
        m=2+m*2;
        init();
        quick(m);
        //pf("%lld ")
        q=(ans[1][1]-1+mod)%mod;
        pf("%lld\n",q);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值