Codeforces Round #273 (Div. 2) 478B - Random Teams Solution




Problem Link :   https://codeforces.com/problemset/problem/478/

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,r,s,e,a,k,i;
    while(cin>>n>>m)
    {
        s=0;
        ///mn
        if(n%m==0)
        {
            a=(n/m)-1;
            for(i=1; i<=m; i++)
                s+=(a*(a+1))/2;

        }
        else
        {
            e=n%m;
            a=n/m;
            for(i=1; i<=e; i++)
                s+=(a*(a+1))/2;

            r=m-e;
            k=(n/m)-1;
            for(i=1; i<=r; i++)
                s+=(k*(k+1))/2;
        }
        cout<<s<<" ";

        ///mx
        k=n-(m-1);
        r=k-1;
        cout<<(r*(r+1))/2<<endl;
    }
}
 
 


No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.