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+1人。最小的为把人数尽可能均分。即有n%m队为n/m+1,n-n%m队为n/m人,最后

算一下朋友对数,一个队友n人,能够产生n*(n-1)/2队朋友。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
long long n,m;
scanf("%I64d%I64d",&n,&m);
long long mini,maxi;
if(n%m==0)
{
mini=n/m;
mini=mini*(mini-1)/2*m;
}
else
{
long long temp=n%m;
long long k=n/m;
mini=(k*(k-1))/2*(m-temp)+k*(k+1)/2*temp;
}
if(m==1)
maxi=n;
else
maxi=n-m+1;
maxi=maxi*(maxi-1)/2;
printf("%I64d %I64d\n",mini,maxi);
return 0;
}

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

  1. 贪心 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 ...

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

  4. Codeforces Round #273 (Div. 2)

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

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

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

  7. CODEFORCES ROUND #273 DIV2

    题目大意: A简单的说就是,有五个人,他们刚开始有B元,经过一系列过程后,给你他们现在分别有的钱,让你求出B(> <难得的傻逼题啊...但是要注意B是正整数!特判0) B有n个人,要分成m ...

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

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

随机推荐

  1. Redis高可用之集群配置(六)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

  2. CPU的主频

    CPU的主频,即CPU内核工作的时钟频率(CPU Clock Speed).通常所说的某某CPU是多少兆赫的(MHZ),而这个多少兆赫就是“CPU的主频”.很多人认为CPU的主频就是其运行速度,其实不 ...

  3. 8.4 正睿暑期集训营 Day1

    目录 2018.8.4 正睿暑期集训营 Day1 A 数对子 B 逆序对 C 盖房子 考试代码 A B C 2018.8.4 正睿暑期集训营 Day1 时间:4.5h(实际) 期望得分:30+50+3 ...

  4. 【学习笔记】python2和python3的input()

    python2中的input()只接受变量作为传入值,非变量内容会报错. >>> user=input("Enter your name:") Enter you ...

  5. [原创]互联网金融App测试介绍

    [原创]互联网金融App测试介绍 前端时间非常忙,终于非常忙的时间过去了,抽时间总结下我现在所在公司理财软件App测试,也各位分享下,也欢迎大家提建议,谢谢! 先介绍下我所在公司的产品特点,公司所研发 ...

  6. px 与 dp, sp换算公式?(转)

    PPI = Pixels per inch,每英寸上的像素数,即 "像素密度" xhdpi: 2.0 hdpi: 1.5 mdpi: 1.0 (baseline) ldpi: 0. ...

  7. 如何调整word中表格某一列占半分比

    1.可以拖动,但是不准确 2.

  8. Snmp学习总结(六)——linux下安装和配置SNMP

    一.安装SNMP 1.1.下载Net-SNMP的源代码 选择一个SNMP版本,比如5.7.1,下载地址如下:http://sourceforge.net/projects/net-snmp/files ...

  9. 如何给Windows Server 2012 R2 添加“磁盘清理”选项

    最近想做一个试验,把我的Windows Server 2008 R2 升级为Server 2012 R2,因为手头没有Raid卡和网卡的驱动,所以做了升级安装,于是那个讨厌的Windows.old出现 ...

  10. 在ASP.NET MVC中使用typeahead.js支持预先输入,即智能提示

    使用typeahead.js可以实现预先输入,即智能提示,本篇在ASP.NET MVC下实现.实现效果如下: 首先是有关城市的模型. public class City { public int Id ...