結果

問題 No.2351 Butterfly in Summer
ユーザー CedeatCedeat
提出日時 2023-06-17 11:04:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 164,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 08:20:27
合計ジャッジ時間 2,852 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int P = 998244353;
template<const int T>
struct ModInt {
  const static int mod = T;
  int x;
  ModInt(int x = 0) : x(x % mod) {}
  int val() { return x; }
  constexpr int moded (int x) const {
    if (x < 0) {
      x += P;
    }
    if (x >= P) {
      x -= P;
    }
    return x;
  }
  ModInt operator + (const ModInt &a) const { int x0 = x; x0 += a.x; return ModInt(x0); }
  ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < mod ? x0 + mod : x0); }
  ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
  ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
  void operator += (const ModInt &a) { x = moded(x + a.x); if (x >= mod) x -= mod; }
  void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
  void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
  void operator /= (const ModInt &a) { *this = *this / a; }
  friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
  ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while(n){
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0;
    while (b) {
      int t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    if (u < 0) u += mod;
    return u;
  }
};
typedef ModInt<P> mint; // mod1 || mod2

void Solve() {
    int n, k;
    cin >> n >> k;
    mint ans = k - 1;
    for (int i = 1; i <= n - 1; i++) {
        ans = ans / k;
    }
    cout << ans * n << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int tt = 1;
    //cin >> tt;
    while (tt--) Solve();

    return 0;
}
0