結果

問題 No.673 カブトムシ
ユーザー Y17Y17
提出日時 2020-01-15 00:25:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,491 bytes
コンパイル時間 1,105 ms
コンパイル使用メモリ 145,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 19:43:37
合計ジャッジ時間 1,916 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<int64_t MOD>

class ModInt {
    int64_t value;
public:
    // constructor
    inline ModInt(int64_t val = 0) noexcept :
        value((val >= MOD) ? (val % MOD) : (val < 0) ? ((val + MOD) % MOD) : val) {}

    // プリミティブ整数型へのキャスト (型の明示:必要)
    template<class Int>
    explicit inline operator Int() const noexcept { return static_cast<Int>(value); }

    inline ModInt inv() const noexcept {
        return ModInt<MOD>::pow(value, MOD-2);
    }

    inline ModInt& operator+=(ModInt x) noexcept {
        if ((value += x.value) >= MOD) value -= MOD;
        return *this;
    }
    inline ModInt& operator-=(ModInt x) noexcept {
        if ((value -= x.value) < 0) value += MOD;
        return *this;
    }
    inline ModInt& operator*=(ModInt x) noexcept {
        value = (value * x.value) % MOD; return *this;
    }

    inline ModInt& operator/=(ModInt x) noexcept {
        value = (value * x.inv().value) % MOD; return *this;
    }

    inline ModInt& operator^=(int64_t x) noexcept {
        value = (int64_t)pow((int64_t)value, x);
        value %= MOD;
        return *this;
    }

    inline ModInt operator+(ModInt x) const noexcept { return ModInt(*this) += x; }
    inline ModInt operator-(ModInt x) const noexcept { return ModInt(*this) -= x; }
    inline ModInt operator*(ModInt x) const noexcept { return ModInt(*this) *= x; }
    inline ModInt operator/(ModInt x) const noexcept { return ModInt(*this) /= x; }
    inline ModInt operator^(int64_t x) const noexcept { return ModInt(*this) ^= x; }
    inline bool operator==(ModInt x) const noexcept { return value == x.value; }
    inline bool operator!=(ModInt x) const noexcept { return !(this->operator==(x)); }

    friend ostream& operator<<(ostream &os, ModInt x) noexcept { os << x.value; return os; }
    friend istream& operator>>(istream &is, ModInt &x) noexcept { is >> x.value, x.value%=MOD; return is; }

    static constexpr inline ModInt pow(int64_t n, int64_t p) noexcept {
        int64_t ret = 1;
        for(; p > 0; p >>= 1) {
            if (p & 1) ret = (ret * n) % MOD;
            n = (n * n) % MOD;
        }
        return ret;
    }
};

using modint = ModInt<int(1e9)+7>;


int main(){
    modint b, c;
    long long n;
    cin >> b >> c >> n;


    modint ans;
    if(c != 1){
        ans = (b * c * ((c^n) - 1)) / (c-1);
    }else{
        ans = b * n;
    }

    cout << ans << endl;
    return 0;
}
0