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

Hint

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个选手。分配完之后,每队伍里2个人可以组成一组,求分配完之后最多的组数和最少的组数....

题解:只要考虑怎么分最多,怎么分最少就好了

    1.   最多的情况就是,先每个队伍分一个人,然后把剩下的全部给到一个队伍里,就是最多的情况    例如:n=10,m=3

                                                   1   1    8

    2、 最少的情况就是,每队分n/m个人,然后剩下的再一个一个的分给每队。                                           例如

                                                   3   3    3+1

代码如下:

#include <stdio.h>
int main()
{
int n,m;
long long kmin=,kmax=;
scanf("%d%d",&n,&m);
int d=n-m+;  //因为把剩下的全部分到一队中的那只队伍里原来就存在一个人了,所以要加1
//printf("d=%d\n",d);
for(int i=d; i>d-; i--)  //这里手贱  用了循环  其实直接就可以乘出来  这里相当于  在d人中中取两个出来(下面的是一样的)
{
kmax*=i;
//printf("kmax=%d\n",kmax);
}
kmax/=;
int x=n/m; //每队均分到多少人
int s=n%m; //剩下的人
for(int i=x; i>x-; i--)
{
kmin*=i;
//printf("kmin=%d\n",kmin);
}
kmin/=;
kmin*=m; //因为是均分,所以一队的分组情况乘以m就是目前所有的
kmin+=s*x;   //最后还要加上,剩下的人,每队给一个直到没有情况。  可以想一下,如果在原来的有x个人的队伍中在家上一个,就会多出来x中取两个的情况,所以这里还剩下s个人,就会多出s*x种
printf("%lld %lld\n",kmin,kmax);
}

                                                  

最新文章

  1. VS 2010一步步开发windows服务(windows service)
  2. Laravel系列 目录结构
  3. Android 广播(内部类)
  4. BZOJ3028: 食物
  5. Java设计模式系列之策略模式
  6. ActiveMQ的配置与使用
  7. 使用 Hibernate 和 MySQL 需要知道的五件事
  8. Linux中ctrl+z 、ctrl+c、 ctrl+d区别
  9. 996.ICU
  10. Java基础(四)线程快速了解
  11. 详谈再论JAVA获取本机IP地址
  12. Java知多少(100)图像处理基础
  13. Next generation sequencing (NGS)二代测序数据预处理与分析
  14. linux ps 命令的查看
  15. 安装了XAMPP,PHP怎么显示中文
  16. eclipse创建activiti6 项目demo
  17. Dubbo学习笔记1:使用Zookeeper搭建服务治理中心
  18. 你需要了解 Windows Phone 8.1 的11件事
  19. 拉格朗日(Lagrange)插值算法
  20. hbase shell中执行list命令报错:ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing

热门文章

  1. iphone开发之用lipo合并模拟器库和真机库,发布一个通用的静态库
  2. Oracle基础 物理备份 冷备份和热备份(转)
  3. 如何让oracle的select强制走索
  4. js实现hashtable的赋值、取值、遍历
  5. 水题2枚 Codevs1464&amp;&amp;Codevs1472
  6. ASP.NET自定义错误页面
  7. JQ笔记
  8. html学习笔记1
  9. String 和 StringBuffer的区别
  10. Part 18 Indexes in sql server