hdu6198 number number number(递推公式黑科技)

number number number

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


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
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6205  6204  6203  6202  6201 
 

Statistic |  Submit |  Discuss |  Note

题意:斐波拉契数列,求不能由这些k个斐波那契数列数组成的最小整数

思路:先手写找规律,再用黑科技代码模板

//递推公式黑科技
#include
using namespace std;
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MEM(x,y) memset(x,y,sizeof(x));
#define bug(x) cout<<"bug"< pii;
using namespace std;
const int maxn=1e3+10;
const int mod=998244353;
ll powmod(ll a,ll b){
    ll res=1;a%=mod;
    assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}
// head
namespace linear_seq {
    const int N=10010;
    ll res[N],base[N],_c[N],_md[N];
    vector Md;
    void mul(ll *a,ll *b,int k) {
        for(int i=0;i=k;i--)
            if (_c[i])
                for(int j=0;j a,vector b) {
    // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
        ll ans=0,pnt=0;
        int k=a.size();
        assert(a.size()==b.size());
        for(int i=0;i=0;p--) {
            mul(res,res,k);
            if ((n>>p)&1) {
                for (int i=k-1;i>=0;i--) res[i+1]=res[i];res[0]=0;
                for(int j=0;j BM(vector s) {
        vector C(1,1),B(1,1);
        int L=0,m=1,b=1;
        for(int n=0;n T=C;
                ll c=mod-d*powmod(b,mod-2)%mod;
                while (C.size() a,ll n) {
        vector c=BM(a);
        c.erase(c.begin());
        for(int i=0;i(a.begin(),a.begin()+c.size()));
    }
};

int main(){
    ll t,n;
//    cin>>t;
    while(cin>>n){
        cout<<(linear_seq::gao(vector{5,13,34,89},n-1)%mod-1)%mod<



你可能感兴趣的:(【ACM之路Bryce模板】,1.5,ACM之路之数学)