您的位置:首页 > 其它

Codeforces Round #273 (Div. 2)(B)排列组合

2016-03-10 13:25 351 查看
B. Random Teams

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

n participants of the competition were split into m teams
in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.

Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

Input

The only line of input contains two integers n and m,
separated by a single space (1 ≤ m ≤ n ≤ 109)
— the number of participants and the number of teams respectively.

Output

The only line of the output should contain two integers kmin and kmax —
the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.

Examples

input
5 1


output
10 10


input
3 2


output
1 1


input
6 3


output
3 6


Note

In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.

In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.

In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2people, maximum
number can be achieved if participants were split on teams of 1, 1 and 4 people.

题意:有n个人,m只队伍,每个队伍至少1人,每个队伍内的人可以俩俩相互称为朋友,问最多,最少有多少对朋友

题解:每个队伍的人数为A[I],那么这支队伍会产生C(A[I],2)对朋友,那么最大的朋友数MAX就是把(n-m)的人数放进一只队伍就是最值了,最小值就是尽可能的将人数平均放进妹纸队伍,求得的和就是最小值、

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;

#define N int(1e5)
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef unsigned long long LL;

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif

#ifdef CDZSC
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
int _time_jc = clock();
#endif
LL n,m;
while (~scanf("%lld%lld",&n,&m))
{
LL mx = 0, mi=0;
LL x= (n - m+1);
mx = x*(x - 1) / 2;

LL left = n%m;
x = n / m;
mi = left*(x*(x + 1)) / 2+(m-left)*(x*(x-1))/2;
printf("%lld %lld\n",mi,mx);
}
#ifdef CDZSC
debug("time: %d\n", int(clock() - _time_jc));
#endif
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: