We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Easy sum
You are viewing a single comment's thread. Return to all 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(){
}