結果

問題 No.1803 Remainder of Sum
ユーザー simansiman
提出日時 2022-11-21 16:09:19
言語 Ruby
(3.3.0)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 315 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 11,876 KB
実行使用メモリ 16,528 KB
最終ジャッジ日時 2023-10-22 06:54:01
合計ジャッジ時間 4,986 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,100 KB
testcase_01 AC 325 ms
16,272 KB
testcase_02 AC 319 ms
16,276 KB
testcase_03 AC 322 ms
16,272 KB
testcase_04 AC 320 ms
16,272 KB
testcase_05 AC 320 ms
16,272 KB
testcase_06 AC 325 ms
16,528 KB
testcase_07 AC 305 ms
16,208 KB
testcase_08 AC 302 ms
16,208 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

T = gets.to_i

T.times do
  n, m = gets.split.map(&:to_i)

  if n < m
    if 2 * n - 1 < m
      puts (n - 1) * (3 + n + 1) / 2
    else
      r = m - n
      l = n - r
      puts (r - 1) * (3 + r + 1) / 2 + l / 2
    end
  else
    if m.even?
      puts (m - 1) / 2 + 1
    else
      puts m / 2
    end
  end
end
0