Description
N participants of the competition were split intom teams in some manner so this each team have at least O NE 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 andm, 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, integers kmin andkma X -the minimum possible number of pairs of friends and the maximum possible number of pairs of friends Respec Tively.
Sample Input
Input
5 1
Output
10 10
Input
3 2
Output
1 1
Input
6 3
Output
3 6
Sample Output
Case 1:0.5
Case 2:1
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 of2 people, maximum number can be achieved if participants were split on teams of1, 1 and C3>4 people.
Test instructions
Give you n people, assign them to the M team, each team must have at least one person, in a team of any two people can become a pair of friends, want you to assign a team, to find the least able to form a friend logarithmic kmin, and the maximum number of teams can be formed logarithmic kmax.
Ideas:
When M=1, that is, there is only one team, then Kmin=kmax=c (n,2), the rest of the situation to maximize the time I we first assign each team to a person, and then the rest of the people all assigned to a team, so that the maximum value, Kmax=c (n-m+1,2), To find the minimum value, we first put each team to the average number of people, the remainder in any choice of a few put a person, kmin= (m-n%m) *c (n/m,2) +N%MC (n/m+n%m,2);
Code:
#include <cstdio>using namespace Std;int main () { long long m,n; Long long Kmin,kmax; while (scanf ("%i64d%i64d", &n,&m)!=eof) { if (m==1) { kmin=kmax=n* (n-1)/2; } else { kmax= (n-m+1) * (N-M)/2; if (n%m==0) { kmin=m* (n/m) * (n/m-1)/2; } else { kmin= (m-n%m) * (n/m) * (n/m-1)/2+ (n%m) * (n/m+1) * (n/m)/2; } } printf ("%i64d%i64d\n", Kmin,kmax); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Random Teams (codeforces Round 273)