結果

問題 No.978 Fibonacci Convolution Easy
ユーザー ysystem7
提出日時 2020-03-17 15:53:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 2,501 ms
コンパイル使用メモリ 209,732 KB
最終ジャッジ日時 2025-01-09 07:32:06
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
ll a[2000005];

int main(){
    ll n,p;
    cin>>n>>p;
    if(n==1) cout<<0<<endl;
    else if(n==2) cout<<1<<endl;
    else{
        ll ans=1;
        ll sum=1;
        a[1]=0;
        a[2]=1;
        for(ll i=3;i<=n;i++){
            a[i]=((p*a[i-1])%mod+a[i-2])%mod;
            sum=(sum+a[i])%mod;
            ans=(ans+(a[i]*sum)%mod)%mod;
        }
        cout<<ans<<endl;
    }
}
0