/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 1ms 772.0 KiB
#3 Accepted 4ms 828.0 KiB
#4 Accepted 26ms 1.312 MiB
#5 Accepted 30ms 2.086 MiB
#6 Accepted 31ms 2.023 MiB

Code

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define int ll
# define double long double
const int N = 2e5 + 2, MOD = 1e9 + 7;
#define deb(x) cout<<#x<<"="<<x<<endl;
#define F first
#define S second


int get(int l, int r) {
    int tmp = (r * (r + 1)) / 2;
    if (l) {
        l--;
        tmp -= (l * (l + 1)) / 2;
    }
    return tmp;
}


void solve() {
    int a, b;
    cin >> a >> b;
    if (a > b)swap(a, b);
    int ans = get(b - a, b - 1) + ((a * (a - 1)) / 2);
    cout << ans;

}

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
//#ifndef ONLINE_JUDGE
//    freopen("output.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
//#endif
    int tt = 1;
    cin >> tt;
    for (int i = 0; i < tt; i++) {
//        cout << "Case " << i + 1 << ": ";
        solve();
        cout << "\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1075 GCD not equal LCM
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 16:09:38
Judged At
2024-10-03 13:08:45
Judged By
Score
100
Total Time
31ms
Peak Memory
2.086 MiB