http://codeforces.com/contest/478/problem/B

B. Random Teams
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
input
5 1
output
10 10
input
3 2
output
1 1
input
6 3
output
3 6
Note

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 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.

解题思路: 求n个人分到m个房间,最多能有几对朋友,最多的情况就是除了一个房间之外的其他房间都只有一个人,剩下的所有人在一个房间

最少的情况就是将所有的人尽可能平均分配到每一个房间

求组合数C(2, n)  = n * (n  - 1) / 2;

 1 #include <stdio.h>
 2 
 3 int main(){
 4     long long n, m, kmin, kmax, res;
 5     while(scanf("%I64d %I64d", &n, &m) != EOF){
 6         if(n % m == ){
 7             res = n / m;
 8             kmin = m * res * (res - ) / ;
 9         }
         else{
             res = n / m;
             kmin = (n % m) * res * (res + ) /  + (m - n % m) * res * (res - ) / ;
         }
 
         n = n - m + ;
         kmax = n * (n - ) / ;
         printf("%I64d %I64d\n", kmin, kmax);
     }
     return ;

20 }

Codeforces Round #273 (Div. 2)-B. Random Teams的更多相关文章

  1. Codeforces Round #273 (Div. 2) B . Random Teams 贪心

    B. Random Teams   n participants of the competition were split into m teams in some manner so that e ...

  2. 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations

    题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...

  3. Codeforces Round #273 (Div. 2)

    A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...

  4. Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心

    A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. codeforces Codeforces Round #273 (Div. 2) 478B

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Round #247 (Div. 2) D. Random Task

    D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #273 (Div. 2)-C. Table Decorations

    http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...

  8. Codeforces Round #273 (Div. 2)-A. Initial Bet

    http://codeforces.com/contest/478/problem/A A. Initial Bet time limit per test 1 second memory limit ...

  9. Codeforces Round #246 (Div. 2) A. Choosing Teams

    给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...

随机推荐

  1. 在linux上部署tomcat服务

    在linux上部署tomcat 1.安装JDK 2.下载tomcat http://tomcat.apache.org/download-70.cgi 3.上传到服务器,并解压 4.上传war包或者已 ...

  2. 【WIP_S9】图论算法

    创建: 2018/06/01 图的概念 有向边 有向图 无向边 无向图 点的次数: 点连接的边的数量 闭路: 起点和重点一样 连接图: 任意两点之间都可到达 无闭路有向图: 没有闭路的有向图 森林: ...

  3. iOS QQ 登录

    QQSDK 看官网的文档,确实让人头疼的一件事,说是两个资源文件,就找到了一个(TencentOpenAPI.framework),Demo中也没有找到. 接下来具体实现: 导入库: 添加SDK依赖的 ...

  4. Dota2技能系统设计分析

    http://blog.csdn.net/langresser_king/article/details/46776701 前两周写完了新游戏的技能系统.虽然也算灵活,但是跟Dota2的技能系统设计比 ...

  5. IT兄弟连 JavaWeb教程 Servlet会话跟踪 Cookie技术原理

    Cookie使用HTTPHeader传递数据.Cookie机制定义了两种报头,Set-Cookie报头和Cookie报头.Set-Cookie报头包含于Web服务器的响应头(ResponseHeade ...

  6. 33、JSONP跨域

    跨域请求数据也是可以的,只不过Ajax这技术不行,而JSONP这种数据格式可以进行跨域.很多年前,浏览器是没有跨域限制的,可以正常跨域,浏览器为了安全和隐私限制了Ajax跨域 JSONP原理就是:将函 ...

  7. 在指定的ChartArea中显示Series

    WinForm的Chart有Series, ChartArea,输出图表就往Serie里扔数据就可以了,很方便是吧.我原想Area和serie有上下级关系,可是我错了,Area和Serie并没有上下级 ...

  8. PAT甲级——1126 Eulerian Path

    我是先在CSDN上发布的这篇文章:https://blog.csdn.net/weixin_44385565/article/details/89155050 1126 Eulerian Path ( ...

  9. PostgreSQL-2-用户权限管理

    1.创建与删除用户 CREATE ROLE rolename; 方法1,创建角色 CREATE USER username; 方法2,创建用户 CREATE USER指令创建的用户默认是有登录权限的, ...

  10. 防止a标签跳转的几种方法

    第一种方法 在a标签的href中添加属性值 <a href="javascript:void(0)"></a> 第二种方法 给a标签添加点击事件,函数的返回 ...