codeforces   478B  Random Teams  解题报告

题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#problem/B

题目:

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

Sample Output

 

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

题意:

n个人分成m队(每队至少一人),竞赛结束后,其中来自同一队的任意两个人可以成为朋友。求最多和最少可以组成多少队朋友?

分析:

排列组合问题。最少:n个人平均分到m个队,组成的队数最少。如果不能平分(即n%m!=0),则将剩下的人平均分到每个组。

最多:m-1个队只有一个人,剩下的人全部在一个队中。

代码:

 #include<cstdio>
#include<iostream>
using namespace std; int main()
{
long long n,m;
long long kmin,kmax;
scanf("%I64d%I64d",&n,&m);
long long a=n/m,b=n%m;
if(b==)//可以平均分(最少)
kmin=m*a*(a-)/;
else //不能平均分(最少)
kmin=(m-b)*a*(a-)/+b*a*(a+)/;
kmax=(n-m+)*(n-m)/;//最多
printf("%I64d %I64d\n",kmin,kmax);
return ;
}

codeforces 478B Random Teams的更多相关文章

  1. codeforces 478B Random Teams 解题报告

    题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...

  2. Codeforces Round #273 (Div. 2)-B. Random Teams

    http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...

  3. B. Random Teams(Codeforces Round 273)

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

  4. 【CODEFORCES】 B. Random Teams

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

  5. 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 ...

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

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

  7. cf478B Random Teams

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

  8. CF478 B. Random Teams 组合数学 简单题

    n participants of the competition were split into m teams in some manner so that each team has at le ...

  9. CodeForces 478B 第八次比赛 B题

    Description n participants of the competition were split into m teams in some manner so that each te ...

随机推荐

  1. DateTimePicker——开源的Android日历类库

    Github托管地址:https://github.com/flavienlaurent/datetimepicker

  2. Java和Android开发IDE---IntelliJ IDEA使用技巧(转)

    以前一直使用的是Eclipse,听别人介绍说IDEA非常不错,也为了以后转Android studio铺垫下.就开始尝试用idea来开发. 这篇文章主要学习了idea的使用技巧. IDEA 全称 In ...

  3. linux环境变量配置总结

    LD_LIBRARY_PATH: 动态库的查找路径设置:方法一: export  LD_LIBRARY_PATH=LD_LIBRARY_PATH:/XXX 但是登出后就失效方法二: 修改~/.bash ...

  4. Jsoup代码解读之一-概述

    Jsoup代码解读之一-概述 今天看到一个用python写的抽取正文的东东,美滋滋的用Java实现了一番,放到了webmagic里,然后发现Jsoup里已经有了…觉得自己各种不靠谱啊!算了,静下心来学 ...

  5. openStack openSource CloudComputing

    <一,> ,OpenStack a few Core Compontents integration with openStack-keystone Identity service1.1 ...

  6. [每日一题] OCP1z0-047 :2013-08-22 正则表达式---[^Ale|ax.r$]'

    正确答案:DE 一.Oracle正则表达式的相关知识点 '[^Ale|ax.r$]': ^:匹配行的开始字符 $:匹配行的结束字符 []:方括号表示指定一个匹配列表,该列表匹配列表中显示的任何表达式. ...

  7. HDU 4861 Couple doubi(找规律|费马定理)

    Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  8. eclipse修改编译路径

    右击项目--properties--java build path--点击source,修改最下方的路径即可

  9. Java 重写(Override)与重载(Overload)

    1.重写(Override) 重写是子类对父类的允许访问的方法的实现过程进行重新编写!返回值和形参都不能改变.即外壳不变,核心重写! 参数列表和返回值类型必须与被重写方法相同. 访问权限必须低于父类中 ...

  10. Database SQL script automation management tools investigation

    Recently researched about database SQL scripts auto management tools, recorded the results here. Res ...