QDC DAY1

  He died suddenly, and relatively autistic mind, a little crash ..

LINK: happy  one once I can certainly write out but I did not mind so collapse launch.

求 $T_n =\displaystyle \sum_{i=0}^{n}F_n$ 其中 $Fn=\displaystyle \sum_{i=0}^{n}f_i \times f_{n-i}$

Where $ f $ is the Fibonacci columns $ f_0 = 1, f_1 = 1 $ ... $ F_n requirements where $ n <= 1e18

 A rather obvious idea is to continue to write Tn simplification and finally found the form of a prefix and then found to O (n) is calculated.

So that only 70 minutes of garbage results.

//#include<bits/stdc++.h>
#include<iomanip>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<deque>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<stack>
#include<algorithm>
#include<vector>
#include<cctype>
#include<utility>
#include<set>
#include<bitset>
#include<map>
#define INF 1000000010
#define ll long long
#define mp(x,y) make_pair(x,y)
#define un unsigned
#define db double
#define EPS 1e-5
#define mod 998244353
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline ll read()
{
    ll x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const ll MAXN=1000010;
ll n;
ll ans,sum;
ll f[MAXN];
signed main()
{
    //freopen("1.in","r",stdin);
    n=read();
    f[0]=1;f[1]=1;
    for(ll i=2;i<=n;++i)f[i]=(f[i-1]+f[i-2])%mod;
    if(n<=20000)
    {
        for(ll i=0;i<=n;++i)
        {
            for(ll j=0;j<=i;++j)
                ans=(ans+f[j]*f[i-j])%mod;
        }
        printf("%lld\n",ans);
        return 0;
    }
    if(n<=1000000)
    {
        for(int i=0;i<=n;++i)sum=(sum+f[i])%mod;
        for(int i=0;i<=n;++i)
        {
            sum=((sum-f[n-i+1])+mod)%mod;
            ans=(ans+f[i]*sum%mod)%mod;
        }
        printf("LLD% \ n- " , ANS);
         return  0 ; 
    } 
    // consider the inclusion and exclusion points 100 are not to good self-closing 
    the printf ( " % LLD \ n- " , ANS);
     return  0 ; 
}
View Code

Continue to think about how to optimize found this is actually inverted triangle to triple sum is not correct so I was considered 2h then abandoned the treatment. Not too direction of thinking right.

$ F_n $ look at this formula. Simply reduces to $ F_n = \ sum_ {i = 0} ^ {n-2} f_i \ times f_ {ni} + f_ {n-1} f_1 + f_nf_0 $

Guess you like

Origin www.cnblogs.com/chdy/p/11619236.html