結果

問題 No.2007 Arbitrary Mod (Easy)
ユーザー kekenxkekenx
提出日時 2024-01-08 22:48:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,881 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 68,536 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-01-08 22:49:00
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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);
    }
  };
  
} // kekenx

using 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;
}


0