結果

問題 No.2467 Sum of Product of Binomial Coefficients
ユーザー tnakao0123tnakao0123
提出日時 2023-09-20 14:03:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,480 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 41,920 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 14:03:55
合計ジャッジ時間 1,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 32 ms
4,380 KB
testcase_02 AC 32 ms
4,380 KB
testcase_03 AC 31 ms
4,376 KB
testcase_04 AC 32 ms
4,380 KB
testcase_05 AC 55 ms
4,380 KB
testcase_06 AC 20 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 27 ms
4,380 KB
testcase_09 AC 37 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2467.cc:  No.2467 Sum of Product of Binomial Coefficients - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

typedef MI<MOD> mi;

/* global variables */

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n, k;
    scanf("%d%d", &n, &k);

    mi sum = 0;
    for (int i = 1; i <= k; i++)
      sum += mi(i + 1).pow(n);

    printf("%d\n", sum.v);
  }
  
  return 0;
}
0