結果
| 問題 |
No.978 Fibonacci Convolution Easy
|
| ユーザー |
|
| 提出日時 | 2020-01-31 22:34:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 925 bytes |
| コンパイル時間 | 1,029 ms |
| コンパイル使用メモリ | 95,364 KB |
| 最終ジャッジ日時 | 2025-01-08 21:18:35 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <queue>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
const ll mod = 1000000007;
ll modinv(ll x, ll m = mod) {
ll b = m;
ll u = 1;
ll v = 0;
ll tmp;
while (b) {
ll t = x / b;
x -= t * b;
tmp = x;
x = b;
b = tmp;
u -= t * v;
tmp = u;
u = v;
v = tmp;
}
u %= m;
if (u < 0) u += m;
return u;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, p;
cin >> n >> p;
vector<ll> a(max(2LL, n));
a[0] = 0;
a[1] = 1;
for (int i = 2; i < n; i++) {
a[i] = (p * a[i-1] + a[i-2]) % mod;
}
ll ans = 0;
ll s = 0;
for (int i = 0; i < n; i++) {
s = (s + a[i]) % mod;
ans = (ans + s * a[i]) % mod;
}
cout << ans << endl;
return 0;
}