結果

問題 No.1281 Cigarette Distribution
ユーザー simansiman
提出日時 2023-03-10 09:59:17
言語 Ruby
(3.3.0)
結果
AC  
実行時間 449 ms / 2,000 ms
コード長 333 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 16,204 KB
最終ジャッジ日時 2023-10-18 06:37:50
合計ジャッジ時間 7,006 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
16,088 KB
testcase_01 AC 84 ms
16,084 KB
testcase_02 AC 83 ms
16,088 KB
testcase_03 AC 82 ms
16,088 KB
testcase_04 AC 84 ms
16,088 KB
testcase_05 AC 84 ms
16,088 KB
testcase_06 AC 83 ms
16,088 KB
testcase_07 AC 82 ms
16,088 KB
testcase_08 AC 82 ms
16,088 KB
testcase_09 AC 82 ms
16,088 KB
testcase_10 AC 82 ms
16,088 KB
testcase_11 AC 82 ms
16,088 KB
testcase_12 AC 171 ms
16,204 KB
testcase_13 AC 301 ms
16,204 KB
testcase_14 AC 242 ms
16,204 KB
testcase_15 AC 189 ms
16,204 KB
testcase_16 AC 222 ms
16,204 KB
testcase_17 AC 84 ms
16,088 KB
testcase_18 AC 441 ms
16,200 KB
testcase_19 AC 449 ms
16,204 KB
testcase_20 AC 446 ms
16,204 KB
testcase_21 AC 266 ms
16,204 KB
testcase_22 AC 318 ms
16,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

1.upto(M) do |x|
  d, m = N.divmod(x)

  l = m
  r = x - l

  v = if m == x - 1
        (d + 1).pow(l, MOD) * d.pow(r, MOD) % MOD
      else
        (d + 1).pow(l + 1, MOD) * d.pow(x - (l + 2), MOD) * (d - 1) % MOD
      end

  if N > 2 * x - 2
    puts v
  else
    puts 0
  end
end
0