結果

問題 No.1803 Remainder of Sum
ユーザー ks2mks2m
提出日時 2022-01-07 22:37:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 2,648 ms
コンパイル使用メモリ 71,720 KB
実行使用メモリ 59,188 KB
最終ジャッジ日時 2023-08-09 03:25:58
合計ジャッジ時間 7,230 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,556 KB
testcase_01 AC 408 ms
57,516 KB
testcase_02 AC 398 ms
57,372 KB
testcase_03 AC 396 ms
57,424 KB
testcase_04 AC 407 ms
59,188 KB
testcase_05 AC 411 ms
57,344 KB
testcase_06 AC 417 ms
57,416 KB
testcase_07 AC 383 ms
57,388 KB
testcase_08 AC 350 ms
59,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		PrintWriter pw = new PrintWriter(System.out);
		for (int z = 0; z < t; z++) {
			String[] sa = br.readLine().split(" ");
			int n = Integer.parseInt(sa[0]);
			int m = Integer.parseInt(sa[1]);

			if (m <= n) {
				pw.println(m / 2);
			} else {
				long x = m / 2;
				long y = m - n;
				long ans1 = x - y;
				long ans2 = (3 + y + 1) * (y - 1) / 2;
				pw.println(ans1 + ans2);
			}
		}
		pw.flush();
		br.close();
	}
}
0