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. cf602B Approximating a Constant Range

    B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 256 megabytes ...

  2. FreeMarker-TemplateLoader

    Java中不乏优秀的模板引擎,Velocity,mvel,FreeMarker等.在构建框架的时候,通常可以拿来即用,但我们需要控制它.最近需要一个数据准备的框架,便选择了FreeMarker,Fre ...

  3. Json.Net学习笔记(十) 保持对象引用

    更多内容见这里:http://www.cnblogs.com/wuyifu/archive/2013/09/03/3299784.html 默认情况下,Json.Net将通过对象的值来序列化它遇到的所 ...

  4. C++排序

    浅谈C++之冒泡排序.希尔排序.快速排序.插入排序.堆排序.基数排序性能对比分析(好戏在后面,有图有真相) 最近一段时间去武汉参加了N多笔试,在几次试题中都出现了排序.偏偏出现了我没怎么看的插入排序, ...

  5. hdu4010 Query On The Trees

    Problem Description We have met so many problems on the tree, so today we will have a query problem ...

  6. C#中操作WMI的类库-实现远程登录共享

    WMI是Windows Management Instrumentation的简称,即:视窗管理规范.在Windows 2000或以后的版本中均安装得有,NT4.0则需要安装WMI的核心组件.通过WM ...

  7. provider: 命名管道提供, error: 40 - 无法打开 SQL Server 联系)

    李和server连接错误. 在连接 SQL Server 2005 时刻.在默认设置 SQL Server 不同意的远程连接可能导致此故障. (provider: 命名管道提供, error: 40 ...

  8. Java使用Protocol Buffers入门四步骤

    Protocol Buffers(简称protobuf)是谷歌的一项技术.用于将结构化的数据序列化.反序列化.经经常使用于网络传输. 这货实际上相似于XML生成和解析.但protobuf的效率高于XM ...

  9. Linux驱动开发学习的一些必要步骤

      1. 学会写简单的makefile 2. 编一应用程序,可以用makefile跑起来 3. 学会写驱动的makefile 4. 写一简单char驱动,makefile编译通过,可以insmod, ...

  10. [转] Nginx + CGI/FastCGI + C/Cpp

    接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...