結果

問題 No.978 Fibonacci Convolution Easy
ユーザー 沙耶花沙耶花
提出日時 2020-01-31 21:42:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 203,272 KB
実行使用メモリ 10,984 KB
最終ジャッジ日時 2023-10-19 00:59:31
合計ジャッジ時間 3,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 22 ms
6,436 KB
testcase_02 AC 12 ms
4,852 KB
testcase_03 AC 49 ms
10,788 KB
testcase_04 AC 15 ms
5,116 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 19 ms
5,908 KB
testcase_07 AC 33 ms
8,216 KB
testcase_08 AC 25 ms
6,700 KB
testcase_09 AC 37 ms
8,940 KB
testcase_10 AC 50 ms
10,984 KB
testcase_11 AC 16 ms
5,380 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 19 ms
5,908 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 21 ms
6,172 KB
testcase_16 AC 50 ms
10,984 KB
testcase_17 AC 50 ms
10,984 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

int main(){
	
	int N;
	cin>>N;
	
	int p;
	cin>>p;
	
	vector<int> a(N);
	a[0] = 0;
	a[1] = 1;
	
	for(int i=2;i<N;i++){
		a[i] = mod(a[i-1]*p);
		a[i] = mod(a[i] + a[i-2]);
	}
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		ans = mod(ans + a[i]);
	}
	
	ans = mod(ans * ans);
	
	for(int i=0;i<N;i++){
		int t = mod(a[i]*a[i]);
		ans = mod(ans + t);
	}
	
	ans = mod(ans * gyakugen(2));
	
	cout<<ans<<endl;
	
	return 0;
}
0