結果
問題 | No.2007 Arbitrary Mod (Easy) |
ユーザー |
![]() |
提出日時 | 2024-01-08 22:48:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,881 bytes |
コンパイル時間 | 664 ms |
コンパイル使用メモリ | 66,560 KB |
最終ジャッジ日時 | 2025-02-18 16:33:52 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <iostream>#include <cassert>#include <utility>namespace kekenx {template<typename T, T mod>class ModInt {public:ModInt(T y): x(y >= 0? y % mod: (mod - (-y) % mod) % mod) {}T get() {return x;}ModInt &operator+=(const ModInt &p) {if ((x += p.x) >= mod) x -= mod;return *this;}ModInt &operator-=(const ModInt &p) {if ((x += mod - p.x) >= mod) x -= mod;return *this;}ModInt &operator*=(const ModInt &p) {x = x * p.x % mod;return *this;}ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}ModInt operator-() const { return ModInt(-x); }ModInt operator+(const ModInt &p) const {return ModInt(*this) += p; }ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p; }ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p; }ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p; }bool operator==(const ModInt &p) const { return x == p.x; }bool operator!=(const ModInt &p) const { return x != p.x; }ModInt pow(long long e) const {T a = 1, p = x;while(e > 0) {if (e % 2 == 0) {p = (p * p) % mod;e /= 2;} else {a = (a * p) % mod;e--;}}return ModInt(a);}private:T x;ModInt inverse() const {T a = x, b = mod, u = 1, v = 0, t;while (b > 0) {t = a / b;a -= t * b;std::swap(a, b);u -= t * v;std::swap(u, v);}return ModInt(u);}};} // kekenxusing namespace std;const long long MOD = 998244353;using mint = kekenx::ModInt<long long, MOD>;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);long long at, n; cin >> at >> n;mint a = mint(at);cout << MOD << '\n' << a.pow(n).get() << endl;return 0;}