Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
409 B
0
Indexable
Never
#define ll long long
#define pb push_back
#include <bits/stdc++.h>
using namespace std;

void solve(){
    ll n,k;
    cin>>n>>k;
    k=min(k,n/2);

    cout<<k*(2*n-2*k-1)<<"\n";
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
	cin>>t;
	while(t--) solve();
}

/* not using formula TLE
 ll ang=0;
    while(k--){
        ang=ang+n-1+n-2;
        n-=2;
    }
    */
Leave a Comment