結果

問題 No.1803 Remainder of Sum
ユーザー SSRSSSRS
提出日時 2022-01-07 22:15:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 162,676 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 18:43:17
合計ジャッジ時間 4,834 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 231 ms
5,376 KB
testcase_02 AC 228 ms
5,376 KB
testcase_03 AC 228 ms
5,376 KB
testcase_04 AC 231 ms
5,376 KB
testcase_05 AC 229 ms
5,376 KB
testcase_06 AC 230 ms
5,376 KB
testcase_07 AC 226 ms
5,376 KB
testcase_08 AC 183 ms
5,376 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