結果

問題 No.980 Fibonacci Convolution Hard
ユーザー leaf_1415leaf_1415
提出日時 2020-01-31 22:23:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 350 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 60,264 KB
実行使用メモリ 34,844 KB
最終ジャッジ日時 2023-10-17 13:36:22
合計ジャッジ時間 10,086 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 345 ms
34,844 KB
testcase_01 AC 344 ms
34,844 KB
testcase_02 AC 346 ms
34,844 KB
testcase_03 AC 346 ms
34,844 KB
testcase_04 AC 346 ms
34,844 KB
testcase_05 AC 345 ms
34,844 KB
testcase_06 AC 345 ms
34,844 KB
testcase_07 AC 345 ms
34,844 KB
testcase_08 AC 348 ms
34,844 KB
testcase_09 AC 346 ms
34,844 KB
testcase_10 AC 349 ms
34,844 KB
testcase_11 AC 350 ms
34,844 KB
testcase_12 AC 350 ms
34,844 KB
testcase_13 AC 346 ms
34,844 KB
testcase_14 AC 349 ms
34,844 KB
testcase_15 AC 346 ms
34,844 KB
testcase_16 AC 330 ms
34,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#define llint long long
#define mod 1000000007

using namespace std;

llint p, Q;
llint a[2000005], f[2000005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> p >> Q;
	
	a[2] = 1;
	for(int i = 3; i < 2000005; i++) a[i] = p*a[i-1]%mod + a[i-2], a[i] %= mod;
	
	f[1] = 0, f[2] = 0, f[3] = 0, f[4] = 1;
	for(int i = 5; i < 2000005; i++){
		f[i] = p*f[i-1]%mod + f[i-2] + a[i-2], f[i] %= mod;
	}
	
	llint x;
	for(int q = 0; q < Q; q++){
		cin >> x;
		cout << f[x] << endl;
	}
	
	return 0;
}
0