Time
limit:1000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u
Description
N participants of the competition were split into m teams in some manner so this each team have at least one participant. After the competition all pair of participants from the same team became friends.
Your task is to write a program that would find the minimum and the maximum number of pairs of friends that could has a form Ed by the end of the competition.
Input
The only line of input contains-integers n and m, separated by a single space (1≤ m ≤ n ≤10 9)-the number of participants and the number ofteams respectively.
Output
The only line of the output should contain, integers kmin and km Ax -the minimum possible number of pairs of friends and the maximum possible number of pairs of friends Respectivel Y.
Sample Input
Input
5 1
Output
10 10
Input
3 2
Output
1 1
Input
6 3
Output
3 6
Hint
In the first sample all the participants get to one team, so there'll be exactly ten pairs of friends.
In the second, sample at any possible arrangement one team would always have both participants and the other team would always have one participant. Thus, the number of pairs of friends is always being equal to one.
In the third sample minimum number of newly formed friendships can is achieved if participants were split on teams consist ing of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.< /c3>
Program Analysis:
The number of elements in the set of I is a[i]. Then its contribution to the answer is v[i]=a[i]* (a[i]-1)/2, so the final answer is V[i] and. And the answer Formula can be translated into:
(A[1]^2+a[2]^2+......+a[m]^2-n)/2. We know (a+b) ^2>=a^2+b^2. So you can guess ansmax= (n-m+1) * (N-M)/2, that is, make a collection as large as possible. The ansmin is approximately equal to the number of each set. I'm going to die of this problem. Don't ask Min to look at someone else's code before.
Program code:
#include <iostream>#include<cstdio>#definell Long Longusing namespacestd; ll M,n,mina,maxa,rest; intMain () {scanf ("%i64d%i64d",&n,&m); Maxa= (n-m+1) * (N-M)/2; Rest=n-m* (n/m); Mina=rest* (n/m+1) * (n/m)/2+ (m-rest) * (n/m) * (n/m-1)/2; printf ("%i64d%i64d\n", Mina,maxa); return 0; }
Codeforces 478B. Random Teams