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. DSP 中关键字extern,cregister,Near ,Far,restrict,volatile

    extern:extern可以置于变量或者函数前,以表示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义.另外,extern也可用来进行链接指定. const: 可以 ...

  2. 007.MySQL-Keepalived搭配脚本01

    vim /etc/keepalived/check_MySQL.sh #!/bin/bash MYSQL=/usr/bin/mysql MYSQL_HOST=localhost MYSQL_USER= ...

  3. SpringMVC框架04——RESTful入门

    1.RESTful的基本概念 REST(Representational State Transfer)表述性状态转移,REST并不是一种创新技术,它指的是一组架构约束条件和原则,符合REST的约束条 ...

  4. js数据结构之列表的详细实现方法

    * 列表用于存放数据量较少的数据结构* 当数据量较大时,不需要对其进行查找.排序的情况下,使用列表也比较方便. 本数据结构在node环境下运行,需要对node有个基本是了解. 1. listSize: ...

  5. web前端实现本地存储

    当我们在提及web前端本地存储的时候,首先需要介绍一下本地化存储的概念和历史.本地化存储从来不是一个新奇的概念,因为web应用程序一直在追求的就是媲美甚至超越桌面应用程序.但是桌面应用程序一直优于we ...

  6. 【WIN10】WIN2D——基本圖形的繪製

    DEMO下載地址:http://yunpan.cn/c3iNuHFFAcr8h (提取码:8e48) 先看一個截圖: 繪製了一些基本形狀. DEMO的繪製代碼都非常簡單,不想在博客裡細說了,看代碼更為 ...

  7. Ubuntu 18.04 更新源

    [原因] 使用国外的源,在更新软件的时候会很慢,换成国内的源会快很多. [命令] 1.备份源文件 sudo cp /etc/apt/sources.list /etc/apt/sources.list ...

  8. kotlin 安装 使用

    插件下载 下载 kotlin 扩展 . 可以 简写 findviewbyid 这些. 比如 id 是 textview 直接 这样赋值 textview.setText("测试文字" ...

  9. 收集的一些MikroTik RouterOS 5.x破解版

    链接:https://pan.baidu.com/s/1RyREMfrpLkpQ-AIcDQES_Q  密码:byhd

  10. Mac 10.12使用free命令(fish)

    前提:要使用free命令,可以安装fish shell,然后在里面安装free插件. 安装fish brew install fish 安装free fish fisher free 使用 fish ...