#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long long int t,n,q,max,r;
cin>>t;
while(t--)
{
cin>>n>>q;
r=q-1;
max=(n*n-((n%r)*(ceil(double(n)/r)*ceil(double(n)/r)))-((r-(n%r))*(floor(double(n)/r)*floor(double(n)/r))))/2;
cout<<((n-1)*n/2)-max<<endl;
}
return 0;
}
#include<math.h>
using namespace std;
int main()
{
long long int t,n,q,max,r;
cin>>t;
while(t--)
{
cin>>n>>q;
r=q-1;
max=(n*n-((n%r)*(ceil(double(n)/r)*ceil(double(n)/r)))-((r-(n%r))*(floor(double(n)/r)*floor(double(n)/r))))/2;
cout<<((n-1)*n/2)-max<<endl;
}
return 0;
}
Command failed: ./a.out <input.txt
ReplyDeleteFloating point exception
plz send proper code
ReplyDelete