結果

問題 No.980 Fibonacci Convolution Hard
ユーザー nejinejinejineji
提出日時 2020-01-31 22:39:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 1,622 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 171,772 KB
実行使用メモリ 36,700 KB
最終ジャッジ日時 2023-10-17 13:43:45
合計ジャッジ時間 11,128 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
36,700 KB
testcase_01 AC 400 ms
36,700 KB
testcase_02 AC 398 ms
36,700 KB
testcase_03 AC 397 ms
36,700 KB
testcase_04 AC 398 ms
36,700 KB
testcase_05 AC 400 ms
36,700 KB
testcase_06 AC 400 ms
36,700 KB
testcase_07 AC 398 ms
36,700 KB
testcase_08 AC 398 ms
36,700 KB
testcase_09 AC 398 ms
36,700 KB
testcase_10 AC 400 ms
36,700 KB
testcase_11 AC 402 ms
36,700 KB
testcase_12 AC 398 ms
36,700 KB
testcase_13 AC 400 ms
36,700 KB
testcase_14 AC 400 ms
36,700 KB
testcase_15 AC 400 ms
36,700 KB
testcase_16 AC 372 ms
36,700 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 p;
        cin >> p;
        ll const MAX = 2e6;
        vll a(2e6 + 1);
        vll b(2e6 + 1, 0);
        a[1] = 0; a[2] = 1;
        REP(i,3,MAX){
                a[i] = mod_p(a[i-2], mod_m(a[i-1], p));
        }
        REP(i,3,MAX){
                b[i] = mod_p(a[i-2], mod_p(b[i-2], mod_m(b[i-1], p)));
        }
        vll ans;
        ll q;
        cin >> q;
        REP(i,1,q){
                ll t;
                cin >> t;
                ans.push_back(b[t]);
        }
        REP(i,0,q-1){
                cout << ans[i] << endl;
        }
}
0