【題解】ZeroJudge f447: 12918 – Lucky Thief

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=f447 (考生答對率: 25.8%)

#include <iostream>
using namespace std;

long long t, n, m;

int main() {
    cin >> t;
    while (t--){
        cin >> n >> m;
        cout << ((m-1)+(m-n))*n/2 << "\n";
    }
}

Python code (credit: Amy Chou)

T = int(input())
for _ in range(T):
    n, m  = map(int, input().split())
    print(n*m - n*(n+1)//2)
分享本文 Share with friends