結果

問題 No.978 Fibonacci Convolution Easy
ユーザー nejinejinejineji
提出日時 2020-01-31 22:07:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 170,492 KB
実行使用メモリ 19,064 KB
最終ジャッジ日時 2023-10-19 01:03:20
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 15 ms
9,568 KB
testcase_02 AC 9 ms
6,536 KB
testcase_03 AC 33 ms
18,272 KB
testcase_04 AC 10 ms
7,260 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 14 ms
8,580 KB
testcase_07 AC 22 ms
13,128 KB
testcase_08 AC 16 ms
10,096 KB
testcase_09 AC 25 ms
14,448 KB
testcase_10 AC 34 ms
19,064 KB
testcase_11 AC 12 ms
7,788 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 14 ms
8,580 KB
testcase_14 AC 5 ms
4,952 KB
testcase_15 AC 14 ms
9,304 KB
testcase_16 AC 35 ms
19,064 KB
testcase_17 AC 34 ms
19,064 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

ll const MOD = 1000000007;
ll mod_p(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
       x %= MOD;
       if (t == 0) {
               return 1;
       }
       else {
               ll v = mod_pow(x, t / 2);
               if (t % 2 == 0) {
                       return v * v % MOD;
               }
               else {
                       return v * v%MOD * x %MOD;
               }
       }
}

ll mod_inv(ll x) {
       return mod_pow(x, MOD - 2);
}

int main(){
        ll n, p;
        cin >> n >> p;
        ll sm = 0;
        ll dd = 0;
        vll a(n+1);
        a[1] = 0;a[2] = 1;
        REP(i,3,n){
                a[i] = mod_p(mod_m(a[i-1], p), a[i-2]) ;
        }
        REP(i,1,n){
                sm += a[i];
                dd += mod_m(a[i], a[i]);
        }
        sm = mod_m(sm, sm);
        cout << mod_m(mod_inv(2), mod_p(sm, dd)) << endl;
}
0