結果

問題 No.980 Fibonacci Convolution Hard
ユーザー furafura
提出日時 2020-02-18 13:57:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,468 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 194,532 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-16 04:08:42
合計ジャッジ時間 7,161 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
11,648 KB
testcase_01 AC 88 ms
11,372 KB
testcase_02 AC 90 ms
11,488 KB
testcase_03 AC 88 ms
11,384 KB
testcase_04 AC 89 ms
11,608 KB
testcase_05 AC 88 ms
11,392 KB
testcase_06 AC 90 ms
11,648 KB
testcase_07 AC 89 ms
11,640 KB
testcase_08 AC 90 ms
11,648 KB
testcase_09 AC 91 ms
11,616 KB
testcase_10 AC 88 ms
11,520 KB
testcase_11 AC 89 ms
11,648 KB
testcase_12 AC 89 ms
11,648 KB
testcase_13 AC 90 ms
11,496 KB
testcase_14 AC 88 ms
11,416 KB
testcase_15 AC 88 ms
11,520 KB
testcase_16 AC 68 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator*(long long y,const mint& m){ return m*y; }

int main(){
	lint p; scanf("%lld",&p);

	mint dp[2000001];
	dp[0]=0;
	dp[1]=0;
	dp[2]=1;
	dp[3]=2*p;
	for(int i=4;i<=2000000;i++) dp[i]=2*p*dp[i-1]-(p*p-2)*dp[i-2]-2*p*dp[i-3]-dp[i-4];

	int q; scanf("%d",&q);
	rep(_,q){
		int n; scanf("%d",&n);
		printf("%d\n",dp[n-2].to_int());
	}

	return 0;
}
0