Codeforces Round #619 (Div. 2)C(构造,容斥)

 #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 ;
}
上一篇:Ajax及跨域


下一篇:Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和