結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー chro_96chro_96
提出日時 2022-11-25 21:33:46
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-02 04:07:33
合計ジャッジ時間 1,513 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long long power_mod (long long a, long  long b, long long mod_num) {
  long long ans = 1LL;
  
  if (b > 0LL) {
    ans = power_mod(a, b/2LL, mod_num);
    ans = (ans * ans) % mod_num;
    if (b%2LL == 1LL) {
      ans = (ans *a) % mod_num;
    }
  }
  
  return ans;
}

int main () {
  long long n = 0LL;
  int m = 0;
  
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  long long mul = 1LL;
  
  long long fact[100001] = {};
  long long invf[100001] = {};
  
  res = scanf("%lld", &n);
  res = scanf("%d", &m);
  
  ans = power_mod(2LL, n, mod_num);
  
  fact[0] = 1LL;
  for (int i = 0; i < m; i++) {
    fact[i+1] = fact[i];
    fact[i+1] *= (long long) (i+1);
    fact[i+1] %= mod_num;
  }
  
  invf[m] = power_mod(fact[m], mod_num-2LL, mod_num);
  for (int i = m; i > 0; i--) {
    invf[i-1] = invf[i];
    invf[i-1] *= (long long)i;
    invf[i-1] %= mod_num;
  }
  
  for (int i = 0; i < m; i++) {
    if (((long long)i) <= n) {
      long long tmp = (mul*invf[i])%mod_num;
      ans += mod_num-tmp;
      mul *= (n-((long long)i))%mod_num;
      mul %= mod_num;
    }
  }
  
  printf("%lld\n", ans%mod_num);
  return 0;
}
0