#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--){
long long n,m;
cin>>n>>m;
long long ans=;
ans=(n*(n+))>>;//总方案数(无论当中是否存在1)
long long temp=n-m;//0的个数
long long x=temp/(+m);//将0均分(猜测这样答案最大)
long long y=temp%(+m);//有y段会多余1个0,长度为x+1
long long z=+m-y;//长度为x的段数
ans-=z*((x+)*x/)+y*((x+)*(x+)/);//总方案数减去中间全是0的字串数量
cout<<ans<<"\n";
}
return ;
}
相关文章
- 09-08Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大
- 09-08Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)
- 09-08C. Moamen and XOR[Codeforces Round #737 (Div. 2)]
- 09-08Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分
- 09-08Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分
- 09-08Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
- 09-08Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
- 09-08Codeforces Round #692 (Div. 2)C. Peaceful Rooks(并查集求环数)
- 09-08Codeforces Round #692 (Div. 2) C. Peaceful Rooks(图论,并查集)
- 09-08Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)