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. SpringCloud之旅第一篇-微服务概念

    一.单体架构的问题 微服务为什么会出现?在学习Springboot的时候知道Springboot极大的简化了我们的开发,我们可以快速的进行业务开发,Springboot单体应用在项目的开发初期能够满足 ...

  2. Unity动画事件

    动画事件添加 var clip = new AnimationClip();//clip,动画剪辑  储存基于动画的关键帧.这里新建动画剪辑 clip.SetCurve ("", ...

  3. Codevs 1312 连续自然数和

    1312 连续自然数和 题目描述 Description 对于一个自然数M,求出所有的连续的自然数段,使得这些连续自然数段的全部数字和为M.eg:1998+1999+2000+2001+2002=10 ...

  4. uoj#283. 直径拆除鸡(构造)

    传送门 好神的构造题 vfk巨巨的题解 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) fo ...

  5. ASP.NET Core MVC内置服务的使用

    ASP.NET Core中的依赖注入可以说是无处不在,其通过创建一个ServiceCollection对象并将服务注册信息以ServiceDescriptor对象的形式添加在其中,其次针对Servic ...

  6. c++的substr()函数

    substr()函数注意:string str =“Hello”: substr(0,4)=“Hell”,0是起始位置,4是要复制的长度,strlen函数输出的是除了结束符"\0" ...

  7. Validation(2)

    站在巨人的肩膀上 spring注解式参数校验 2016年06月15日 15:42:47 God_Ming 阅读数:57021 标签: springhibernatevalidator 更多 个人分类: ...

  8. one jar(转)

    http://blog.csdn.net/kabini/article/details/1598827

  9. 《Python网络爬虫之三种数据解析方式》

    引入 回顾requests实现数据爬取的流程 指定url 基于requests模块发起请求 获取响应对象中的数据 进行持久化存储 其实,在上述流程中还需要较为重要的一步,就是在持久化存储之前需要进行指 ...

  10. 洛谷2758(字符串dp)

    题目传送 记得这是我初学dp时的一道题 虽说就像LCS一样搞一搞即可 但我还是写挂了qwq #include <cstdio> #include <cstring> #incl ...