• + 0 comments

    //c++ code

    include

    using namespace std;

    define endl '\n'

    define ig cin.ignore()

    define GET_FASTER ios_base::sync_with_stdio(false); cin.tie(NULL)

    typedef long long int ll; const ll mx= LLONG_MAX; const ll mn= LLONG_MIN; const ll MOD= 1e9+7; bool descending_order(int x, int y){return x>y;}

    long long nth_term(long long n){ return (n+(n*n))/2; }

    int main(){

    GET_FASTER;
    
    int t;
    cin>> t;
    
    while(t--){
        long long n,m;
        cin>> n>> m;
    
        long long rem= n %m;
        long long div= n/m;
        long long tem= m-1;
    
        long long result;
    
        result = ((nth_term(tem)*div)+ nth_term(rem));
    
        cout<< result<< endl;
    
    }
    
    
    return 0;
    

    }