結果

問題 No.1184 Hà Nội
ユーザー kekenxkekenx
提出日時 2024-01-09 18:32:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,879 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 68,664 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-09 18:32:24
合計ジャッジ時間 2,405 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 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;

using mint = kekenx::ModInt<long long, 998244353>;

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

  long long N, L; cin >> N >> L;
  long long M = N % L == 0? N / L : N / L + 1;
  cout << (mint(2).pow(M) - mint(1)).get() << endl;
  return 0;
}

0