結果

問題 No.2351 Butterfly in Summer
ユーザー AnchorBlues
提出日時 2023-09-26 14:32:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,682 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 193,968 KB
最終ジャッジ日時 2025-02-17 02:25:57
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0