组合——Program B

    CodeForces 478B

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

  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.

 

Sample Input

 
Input
  5  1
Output
 10  10
Input
3 2
Output
1 1
Input
6 3
Output
3 6




题目大意:将n个人分到m个队中,求队中成为朋友个数的最大值与最小值。

分析:此题是一个组合问题.










代码如下:

#include <iostream>
#include<cstdio>




using namespace std;
long long n, m;
long long cal(long long a)
{
  return a*(a-1)/2;
}
int main()
{
  while(scanf("%lld %lld",&n,&m)==2)
  {
    long long a=n/m;
    printf("%lld %lld ", cal(a)*(m-n%m) + cal(a+1)*(n%m), cal(n-m+1));
  }
return 0;
}

 
原文地址:https://www.cnblogs.com/xl1164191281/p/4749093.html