题目
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 kminand 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
题意:
把n个人分成m组,每一组两两会成为朋友,要求形成尽可能多对朋友
思路:
原理是这样的
假设5个人必须分成三组
先分
组1:1
组2:1
组3:1
还有两个人再分一个人:
组1:2
组2:1
组3:1
最后一个人:
如果分到组1,新形成两对朋友。
如果分到组2和组3,只能新形成一对朋友。
所以想到要尽可能的把其中一个组人数弄成可以达到的最大剩下的组都是一个人。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
long long kmi,kma,n,m;
int main()
{
scanf("%I64d%I64d",&n,&m);
long long b=n/m,c=n%m;
kmi=c*b*(b+1)/2+(m-c)*b*(b-1)/2;
kma=(n-m+1)*(n-m)/2;
printf("%I64d %I64d\n",kmi,kma);
return 0;
}