Codeforces Round #273 (Div. 2) 478B - Random Teams Solution
Problem Link : https://codeforces.com/problemset/problem/478/B
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