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. 关于Linux

    这是一个2B让我写的关于Linux的一点东西. 其实我对Linux一直都是持有一种很尊敬的态度,作为一个非商业性的操作系统,能够成长成这样简直是不可思议,有一种Dota在游戏界的感觉,很让人佩服.但是 ...

  2. BFS 10.1.5.253 1502

    http://10.1.5.253/acmhome/problemdetail.do?&method=showdetail&id=1502 //1502 #include <st ...

  3. ubuntu12编译openwrt

    搭建编译环境 Ubuntu x64 12.04下的命令: sudo apt-get install subversion sudo apt-get install git sudo apt-get i ...

  4. linux防火墙 基础知识

    转 http://drops.wooyun.org/tips/1424 iptables介绍 linux的包过滤功能,即linux防火墙,它由netfilter 和 iptables 两个组件组成. ...

  5. mybatis logback打印sql

    <?xml version="1.0" encoding="UTF-8" ?><configuration> <contextNa ...

  6. 全情投入是做好工作的基础——Leo鉴书39

    很多人都有:“内向的人则不擅长社交,只能会活得很封闭”的思想,于是不少内向的朋友要么认为只有扭曲自己的性格变得外向才能在社会上吃得开,才能很爽的行走职场:要么就决定完全封闭自己活在孤独之中,其实以上两 ...

  7. [转] 【开源访谈】Muduo 作者陈硕访谈实录

    关于开源访谈 开源访谈是开源中国推出的一系列针对国内优秀开源软件作者的访谈,以文字的方式记录并传播.我们希望开源访谈能全面的展现国内开源软件.开源软件作者的现状,着实推动国内开源软件的应用与发展. [ ...

  8. ASP.NET-FineUI开发实践-15

    1.按条件控制Grid不可编辑     Grid编辑其实用到的不多...但是也有要控制权限或者其他条件不能编辑的情况其实挺简单,学过extjs的知道,我现在也只是写前台了,没有写到后台事件,有时间再说 ...

  9. SQL Server强制删除发布

    今日发现SQL Server 中 存在以前(系统还原前)的发布内容,使用鼠标->右键,选择删除,失败.   可使用语句: EXEC SP_REMOVEDBREPLICATION '发布数据库名称 ...

  10. (转)Css样式兼容IE6,IE7,FIREFOX的写法

    根据FF和IE对一些符号识别的差异,我们可以单独对FF以及IE定义样式,例子: 区别IE6与FF:          background:orange;*background:blue;   区别I ...