結果

問題 No.2141 Enumeratest
コンテスト
ユーザー magurofly
提出日時 2022-12-02 22:13:27
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 399 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 67 ms
コンパイル使用メモリ 9,088 KB
実行使用メモリ 22,784 KB
最終ジャッジ日時 2026-04-26 02:35:52
合計ジャッジ時間 4,298 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

N, M = gets.split.map(&:to_i)
MOD = 998244353

factorial = [1]
(1 .. M).each do |i|
    factorial << factorial[-1] * i % MOD
end

ans = factorial[M]
div = 1
larger = (M + N - 1) / N
smaller = M / N
larger_count = M % N
smaller_count = N - larger_count
div *= factorial[larger].pow(larger_count, MOD)
div *= factorial[smaller].pow(smaller_count, MOD)
ans *= div.pow(MOD - 2, MOD)
ans %= MOD

puts ans
0