結果

問題 No.978 Fibonacci Convolution Easy
ユーザー finefine
提出日時 2020-01-31 21:33:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 167,268 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 00:56:38
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 11 ms
4,348 KB
testcase_02 AC 7 ms
4,348 KB
testcase_03 AC 23 ms
4,348 KB
testcase_04 AC 8 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 10 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 12 ms
4,348 KB
testcase_09 AC 18 ms
4,348 KB
testcase_10 AC 24 ms
4,348 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 25 ms
4,348 KB
testcase_17 AC 24 ms
4,348 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;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll p;
    cin >> p;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll a1 = 0, a2 = 1;
    ll ans = a1 * a1 + a2 * a1 + a2 * a2;
    ll sum = a1 + a2;
    for (int i = 3; i <= n; ++i) {
        ll a3 = (a2 * p % MOD + a1) % MOD;
        a1 = a2;
        a2 = a3;
        (sum += a2) %= MOD;
        (ans += sum * a2 % MOD) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}
0