B - B

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

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

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

题解:

n个人,把他们分配到m支队伍中去,每支队伍至少要有一个人,在一个队伍中的任意两个人都可以成为一对朋友,要你分配队伍,求出最少能够形成的朋友对数min,和最多能形成的队伍对数max.

思路:

当m=1的时候,也就是只有一支队伍,那么kmin=kmax=C(n,2);其余的情况求最大值的 时候我我们先把每个队伍分配一个人,然后把剩余的人全部分配到一个队伍,这样求得的为最大值,max=C(n-m+1,2),求最小值的时候,我们先把每个队伍都平均分配人数,剩余的人在任意选几个放一个人。

#include<iostream>
using namespace std;
int main()
{
long long minnum,maxnum,n,u,m,t,s,p;
cin>>n>>m;
if(m==)
{
minnum= maxnum=n*(n-)/;
cout<<minnum<<" "<<maxnum<<endl;
}
else
{
t=n/m;
p=n-t*m;
minnum=(m-p)*t*(t-)/+p*t*(t+)/;
u=n-m+;
maxnum=u*(u-)/;
cout<<minnum<<" "<<maxnum<<endl;
}
}

CodeForces 478B 第六周比赛B题的更多相关文章

  1. CodeForces 569A 第六周比赛C踢

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

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

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

  3. LightOJ 1317 第六周比赛A题

    A - A Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Description Y ...

  4. HDU2669 第六周练习I题(扩展欧几里算法)

    第六周练习I题 I - 数论,线性方程 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  5. Codeforces 559A 第六周 O题

    Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...

  6. 第十六周oj刷题——Problem I: 改错题:类中私有成员的訪问

    Description 改错题: 设计一个日期类和时间类,并编写全局函数display用于显示日期和时间. 要求:display函数作为类外的普通函数,而不是成员函数 在主函数中调用display函数 ...

  7. 第十六周oj刷题——Problem E: B 构造函数和析构函数

    Description 在建立类对象时系统自己主动该类的构造函数完毕对象的初始化工作, 当类对象生命周期结束时,系统在释放对象空间之前自己主动调用析构函数. 此题要求: 依据主程序(main函数)和程 ...

  8. 暑假集训第一周比赛C题

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83146#problem/C C - 学 Crawling in process... C ...

  9. CodeForces 569A 第八次比赛 C题

    Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...

随机推荐

  1. UNIX环境下的共享内存

    好久没更新博客了,最近几个月一直在忙项目,现在终于有时间进一步学习了.这次记录的是unix环境中共享内存的使用方法.  在我理解,共享内存就是在内存中开辟一段空间,各个毫不相干的进程就可以通过访问这段 ...

  2. UVALive4513 Stammering Aliens(哈希法,后缀数组)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12580 [思路] 求出现次数不小于k次的最长可重叠子串和最后的出现 ...

  3. [Audio processing] wav音频文件读取int和double数组的关系

    直接读取wav文件是int数组,但是有一些实现返回的是double数组,还有些输入是double数组:那我们要互相调用的时候还是要看看两者到底有什么关系,其实很简单. 以单身道,16bit为例 /** ...

  4. poj1013

    题目大意:假造的银币 Sally Jones有一些游客给的银币,但是只有11枚是真正的银币(有一枚是假的),从颜色和大小是无法区分真比还是假币的,但是它的重量和真币是不同的,Sally Jones它是 ...

  5. 关于openoffice英文乱码的问题

    首先选中乱码的部分,然后在右边的侧栏中看到其字体,尝试改变它的字体,看会不会显示正常,如果可以,先记住这两种字体.然后:    工具->选项->字体        然后在使用替换表打上勾, ...

  6. 如何把textfield或者textview中长按出现的(全选,复制,粘贴)显示成中文

    ios在配置文件info.plist 中添加Localiztion native development region (本地化设置) 设置为 china

  7. POJ 3414 Pots ( BFS , 打印路径 )

    题意: 给你两个空瓶子,只有三种操作 一.把一个瓶子灌满 二.把一个瓶子清空 三.把一个瓶子里面的水灌到另一个瓶子里面去(倒满之后要是还存在水那就依然在那个瓶子里面,或者被灌的瓶子有可能没满) 思路: ...

  8. struts2入门程序

    struts2入门程序 1.示例 搭建编程环境就先不说了,这里假设已经搭建好了编程环境,并且下好了strut2的jar包,接下来程序. 1.1 新建web项目 点击File->New->D ...

  9. 从Delphi 7升级到Delphi XE

    Delphi 7和XE中间有好几个版本号,可都不太流行,一是由于Delphi有些边缘化,二是7在XP环境下是近乎完美的版本号.市场上关于delphi的书越来越少,提供从7升级到XE介绍的资料差点儿没用 ...

  10. [PWA] 15. Using The IDB Cache And Display Entries

    We want to use IDB to store the wittr messages. The logic is when the page start: service worker wil ...