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. vuex使用modules namespaced 后,模块名不同,函数名相同时候在组件中分发Action

    你在组件中使用 this.$store.dispatch('xxx') 分发 action,或者使用 mapActions 辅助函数将组件的 methods 映射为 store.dispatch 调用 ...

  2. 解决vue项目打包后背景图片找不到的问题

    在build->webpack.base.conf.js里添加一句代码: 具体位置在module->rules下 publicPath:"../../",

  3. sqrt

    sqrt特别慢,两边同时平方,尽量避免开方.

  4. Codeforces-1084C

    title: Codeforces-1084C date: 2018-12-13 16:02:04 tags: acm 刷题 categories: Codeforces 概述 好久没写博客了,,,最 ...

  5. SVN同步时报错:“Previous operation has not finished; run 'cleanup' if it was interrupted”

    SVN同步时报错:“Previous operation has not finished; run 'cleanup' if it was interrupted” 这大概是SVN之前的操作没有完成 ...

  6. 蓝牙设备探测工具blueranger

    蓝牙设备探测工具blueranger   blueranger是Kali Linux预安装的一款蓝牙探测工具.该工具通过向指定设备发送蓝牙L2CAP协议的ping包,创建连接.由于大部分蓝牙设备对pi ...

  7. hadoop 基础视频1

    hadoop 基础视频1 一, 大致内容: 1, 源起与体系结构2,实施Hadoop 集群3,分布式HDFS, 大数据存储实战4,Map-Reduce 体系架构5,Map-Reduce 数据分析之一 ...

  8. native与ascii互转

    package org.edujks.schoolapp.schoolbasedresearch.schoolsubject.action; public class DecodeUtil { /** ...

  9. 狗日的系统之家下载的Windows 10 1803/1809系统不干净,捆绑自动安装腾讯关键等软件

    特此记录一下,如果网友看到这篇文章请不要下载它们家的,捆绑软件,并且安装自动设置了账号,这还不是修改,是啥? 我们都知道现在iso文件基本都是网友自行制作的,从微软下载的文件自行制作成iso,也就是现 ...

  10. [Go] defer 语句

    Go 还有一些特有的流程控制语句,其中一个就是 defer 语句.该语句用于延迟调用指定的函数,它只能出现在函数的内部,由 defer 关键字以及针对某个函数的调用表达式组成.这里被调用的函数称为 延 ...