总结
题意:要求构造一个二进制字符串,求最大的连续字符串包含字符1的方案数
正难反易,求最小的连续的字符串只包含字符0的数量,ans减去它即可
m个1可以构造m+1个空隙
用n-m个0去填就完事
signed main()
{
IOS;
//file();
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int ans=n*(n+1)/2;
n=n-m;
m++;
int a=n/m,b=n%m;
ans-=a*(a+1)/2*(m-b);
if(b%m)
a++;
ans-=a*(a+1)/2*b;
cout<<ans<<endl;
}
return 0;
}