結果

問題 No.978 Fibonacci Convolution Easy
ユーザー misora192misora192
提出日時 2020-05-09 12:17:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 165,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-19 03:53:22
合計ジャッジ時間 2,886 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 11 ms
4,376 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 25 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 17 ms
4,380 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 19 ms
4,376 KB
testcase_10 AC 26 ms
4,376 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 26 ms
4,376 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

// pow
ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b & 1) {
		return a * pow(a, b - 1);
	} else {
	ll d = pow(a, b / 2);
	return d * d;
	}
}

ll powmod(ll a, ll b){
	if(b == 0) return 1;
	if(b & 1) {
		return a * powmod(a, b - 1) % MOD;
	} else {
		ll d = powmod(a, b / 2) % MOD;
		return d * d % MOD;
	}
}

ll sub(ll a, ll b){
	return a + MOD - b;
}

ll inv(ll a){
	return powmod(a, MOD - 2);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, p;
	cin >> n >> p;

	if(n == 1){
		cout << 0 << endl;
		return 0;
	}

	ll y = 1;
	ll z = 0;
	ll sm = y + z;
	rep(i, n - 2){
		ll x = p * y + z;
		x %= MOD;
		sm += x;
		sm %= MOD;
		z = y;
		y = x;
	}

	y = 1;
	z = 0;
	ll dg = y * y + z * z;
	rep(i, n - 2){
		ll x = p * y + z;
		x %= MOD;
		dg += x * x;
		dg %= MOD;
		z = y;
		y = x;
	}

	ll ans = dg;
	ll ot = sm * sm;
	ot %= MOD;
	ot += MOD - dg;
	ot %= MOD;
	ot *= inv(2);

	ans += ot;
	ans %= MOD;

	cout << ans << endl;
}
0