結果

問題 No.1275 綺麗な式
ユーザー ktr216ktr216
提出日時 2020-10-30 22:49:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 885 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 174,724 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 07:52:54
合計ジャッジ時間 4,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 ms
4,380 KB
testcase_41 WA -
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;

ll a, b, n, MOD = 1e9 + 7;
map<ll, ll> mp;

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

ll solve(ll n) {
    if (mp.find(n) != mp.end()) return mp[n];
    if (n == 0) {
        mp[0] = 2;
        return mp[0];
    }
    if (n == 1) {
        mp[1] = 2 * a;
        return mp[1];
    }
    if (n % 2) {
        mp[n] = (solve(n / 2 + 1) * solve(n / 2) - ((mod_pow(a * a - b, n / 2, MOD) * 2 * a) % MOD) + MOD) % MOD;
    } else {
        mp[n] = (solve(n / 2) * solve(n / 2) - ((mod_pow(a * a - b, n / 2, MOD) * 2) % MOD) + MOD) % MOD;
    }
    return mp[n];
}

int main() {
    cin >> a >> b >> n;
    cout << solve(n) << "\n";
}
0