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);
}

                                                  

CodeForces 478B 第八次比赛 B题的更多相关文章

  1. CodeForces 569A 第八次比赛 C题

    Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...

  2. CodeForces 478B 第六周比赛B题

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

  3. LightOJ 1317 第八次比赛 A 题

    Description You probably have played the game "Throwing Balls into the Basket". It is a si ...

  4. ACM第六周竞赛题目——B CodeForces 478B

    B - B Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  5. codeforces 478B Random Teams

    codeforces   478B  Random Teams  解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...

  6. CSDN挑战编程——《金色十月线上编程比赛第二题:解密》

    金色十月线上编程比赛第二题:解密 题目详情: 小强是一名学生, 同一时候他也是一个黑客. 考试结束后不久.他吃惊的发现自己的高等数学科目竟然挂了,于是他果断入侵了学校教务部站点. 在入侵的过程中.他发 ...

  7. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  8. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  9. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

随机推荐

  1. EasyUI设置复选框单选操作

    Html 代码: <td align="left" colspan="2">                    <input type=& ...

  2. 重构5-Pull Up Field(字段上移)

    我们来看看一个和上移方法十分类似的重构.我们处理的不是方法,而是字段. public abstract class Account{} public class CheckingAccount ext ...

  3. PHP删除符合条件的整个目录

    <?php /** * @name delFile函数与delDir函数一起使用, 删除符合条件的整个目录 * @param string $path 指定操作路径 * @return null ...

  4. hdu 4409 LCA

    思路:就是个比较裸的LCA了,不过要注意的是,如果a和b的公共祖先是a,那么答案就是farther[a]. #include<cstring> #include<cmath> ...

  5. UIActionSheet警告,提示调用showFromTabBar方法

    UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"选择图片" delegate:(self) c ...

  6. 阿里巴巴的分布式应用框架-dubbo负载均衡策略--- 一致哈希算法

    dubbo是阿里巴巴公司开发的一个开源分布式应用框架,基于服务的发布者和订阅者,服务者启动服务向注册中心发布自己的服务:消费者(订阅者)启动服务器向注册中心订阅所需要的服务.注册中心将订阅的服务注册列 ...

  7. Every student in every school should have the opportunity to learn to code

    “I think everybody in this country should learn how to program a computerbecause it teaches you how ...

  8. 【转载]】Microsoft SQL Server, 错误:4064的解决方法

    SQL SERVER – Fix : Error: 4064 – Cannot open user default database. Login failed. Login failed for u ...

  9. JQuery处理json与ajax返回JSON实例

    一.JSON的一些基础知识. JSON中对象通过“{}”来标识,一个“{}”代表一个对象,如{“AreaId”:”123”},对象的值是键值对的形式(key:value). “[]”,标识数组,数组内 ...

  10. 谷歌浏览器Chrome不再支持showModalDialog的解决办法

    问题重现 弹出窗口编码: JavaScript 0 1 2 3 4 5 6 7   var obj = new Object();   var retval = window.showModalDia ...