codeforces #619 div.2 (C - Ayoub's function)

Release like a formula
to make a maximum interval having 1, uses inclusion and exclusion
like are assumed as a
number is n * (n-1) / 2
minus the number range 0 to
the total number of the maximum to make the
necessary 0 so that the number of the minimum interval
used to divide a total of m + 1 of section
identical as possible so that each interval number 0

Code:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll t,n,m;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        if(m==0)
        {cout<<"0"<<endl;
        continue;}
        if(n==1)
        {cout<<"1"<<endl;
        continue;}
        ll ans=n*(n-1)/2;
        ans+=m;
        ////////////////////////////////////////////
        ll c0=n-m;//c0为0的个数
        ll op=m+1;//op为由1划分的区块数
        if(c0%op==0)
        {
            ll kk=c0/op;
            ans-=op*kk*(kk-1)/2;
            cout<<ans<<endl;
        }
        else
        {
            ll kk=c0/op;
            ll mod=c0%op;
            ll aa=mod*(kk+1)*(kk)/2;
            ll bb=(op-mod)*kk*(kk-1)/2;
            ans-=(aa+bb);
            cout<<ans<<endl;
        }
    }
    return 0;
}

Published 36 original articles · won praise 4 · Views 1399

Guess you like

Origin blog.csdn.net/qq_43781431/article/details/104313372