結果

問題 No.1803 Remainder of Sum
ユーザー SSRSSSRS
提出日時 2022-01-07 22:15:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 163,708 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 03:19:50
合計ジャッジ時間 4,567 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 207 ms
4,384 KB
testcase_02 AC 203 ms
4,380 KB
testcase_03 AC 210 ms
4,384 KB
testcase_04 AC 212 ms
4,384 KB
testcase_05 AC 210 ms
4,380 KB
testcase_06 AC 214 ms
4,380 KB
testcase_07 AC 203 ms
4,380 KB
testcase_08 AC 166 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long ap_sum(long long a, long long b){
  return (b + a) * (b - a + 1) / 2;
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N, M;
    cin >> N >> M;
    if (N < M){
      if (M % 2 == 0){
        long long ans = N - M / 2;
        ans += ap_sum(3, M - N + 1);
        cout << ans << endl;
      } else {
        long long ans = N - M / 2 - 1;
        ans += ap_sum(3, M - N + 1);
        cout << ans << endl;
      }
    } else {
      cout << M / 2 << endl;
    }
  }
}
0