結果

問題 No.2351 Butterfly in Summer
ユーザー AnchorBluesAnchorBlues
提出日時 2023-09-26 14:32:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,682 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 200,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 14:32:30
合計ジャッジ時間 3,912 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll INF = 1LL << 60;
const ll Z = 998244353;

template <class T>
void chmax(T& a, T b) {
    if (b > a) a = b;
}
template <class T>
void chmin(T& a, T b) {
    if (b < a) a = b;
}

template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept {
    return os << "(" << x.first << ", " << x.second << ")";
}

template <typename T>
void print_vector(vector<T> a) {
    cout << '[';
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i != a.size() - 1) {
            cout << ", ";
        }
    }
    cout << ']' << endl;
}

template <ll MOD>
class ModInt {
   public:
    constexpr ModInt() { val = 0; }
    constexpr ModInt(ll v) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr ll getval() const noexcept { return val; }
    constexpr ModInt operator-() const noexcept {
        if (val == 0) return 0;
        return MOD - val;
    }
    constexpr ModInt operator+(const ModInt& r) const noexcept {
        return ModInt(*this) += r;
    }
    constexpr ModInt operator-(const ModInt& r) const noexcept {
        return ModInt(*this) -= r;
    }
    constexpr ModInt operator*(const ModInt& r) const noexcept {
        return ModInt(*this) *= r;
    }
    constexpr ModInt operator/(const ModInt& r) const noexcept {
        return ModInt(*this) /= r;
    }
    constexpr ModInt& operator+=(const ModInt& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr ModInt& operator-=(const ModInt& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr ModInt& operator*=(const ModInt& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr ModInt& operator/=(const ModInt& r) noexcept {
        ll a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            std::swap(a, b);
            u -= t * v;
            std::swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator==(const ModInt& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!=(const ModInt& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr std::ostream& operator<<(std::ostream& os,
                                              const ModInt<MOD>& x) noexcept {
        return os << x.val;
    }
    // n乗 を MOD で割った余り
    constexpr ModInt<MOD> pow(ll n) noexcept {
        if (n == 0) return 1;
        auto t = this->pow(n / 2);
        t = t * t;
        if (n & 1) t = t * val;
        return t;
    }
    // 逆元
    constexpr ModInt<MOD> inv() noexcept {
        ModInt<MOD> one = 1;
        return one / *this;
    }
    ModInt<MOD>& operator=(ll v) noexcept {
        val = v % MOD;
        return *this;
    }
    ModInt<MOD>& operator=(const ModInt<MOD>& v) noexcept {
        val = v.val % MOD;
        return *this;
    }

   private:
    ll val;
};

using mint = ModInt<Z>;

void solve() {
    ll N, K;
    cin >> N >> K;
    mint a = mint(K) * mint(K - 1) * mint(N);
    mint b = mint(K).pow(N);
    std::cout << a / b << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}
0