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.

虽然是道水题,但是我还是想说下。

题意:已知∑ai=n(i从1到m),求∑C(2,ai)的最大值和最小值

要求ai>=1

化简:原式=(∑(ai^2)-n)/2

所以只要求出∑(ai^2)的最值即可

考虑我们分配2个数x,y,根据贪心:

x^2+y^2<=(x-1)^2+(y+1)^2  (x<y)

所以要让平方和更大,我们应该从x中拿更多的给y,最终就是x=1,y尽量大

y再和其他数比较,也是同样的结果,最终,我们得到:

当m-1个为1,1个为n-m+1的时候,得到最大值

同理,当m个数尽量平均的时候,就得到最小值。

#include<cstdio>
#include<iostream> #define LL long long using namespace std; int main()
{
LL n,m;
cin>>n>>m;
LL tmax=,tmin=;
tmax=m-+(n-m+)*(n-m+);
LL a=n/m;
LL b=n%m;
int i=;
tmin=b*(a+)*(a+)+(m-b)*(a*a); cout<<(tmin-n)/<<" "<<(tmax-n)/<<endl;
return ;
}

CF478 B. Random Teams 组合数学 简单题的更多相关文章

  1. 【CODEFORCES】 B. Random Teams

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. BZOJ 2683: 简单题

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 913  Solved: 379[Submit][Status][Discuss] ...

  3. 【BZOJ-1176&2683】Mokia&简单题 CDQ分治

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  4. Bzoj4066 简单题

    Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 2185  Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...

  5. Bzoj2683 简单题

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1071  Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...

  6. 这样leetcode简单题都更完了

    这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...

  7. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

  8. HDU 1753 大明A+B(字符串模拟,简单题)

    简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...

  9. 团体程序设计天梯赛-练习集L1-014. 简单题

    L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...

随机推荐

  1. 2-1-1 GDI

    主要内容:介绍Windows图形设备接口(GDI)及相关概念 1.Windows图形设备接口(GDI) <1>Windows图形设备接口(GDI),是为与设备无关的图形设计的.  所谓设备 ...

  2. MySQL性能参数详解 - max_connect_errors

    max_connect_errors是一个MySQL中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码的情况.max_connect_errors的值与性能并无太大关系. 默认情 ...

  3. Linux驱动设计—— 部分系统调用函数原型

    cdev结构体和它的初始化注册函数原型 struct cdev {   struct kobject kobj;          // 每个 cdev 都是一个 kobject   struct m ...

  4. IntelliJ IDEA 开发前的设置

    1.IntelliJ IDEA 显示行号方法 设置方法:File->Settings->Editor->General->Appearance->Show line nu ...

  5. 强化学习之 免模型学习(model-free based learning)

    强化学习之 免模型学习(model-free based learning) ------ 蒙特卡罗强化学习 与 时序查分学习 ------ 部分节选自周志华老师的教材<机器学习> 由于现 ...

  6. Unity3d 无网络权限下打开网站

    有人问“更多游戏”没有网络权限怎么实现,其实调用浏览器访问外部链接不需要网络通讯权限,代码如下: Uri moreGame = Uri.parse("http://wapgame.189.c ...

  7. Unity3D研究院编辑器之脚本获取资源内存和硬盘大小

    内存 使用Profiler可以查看某个资源的内存占用情况,但是必须启动游戏,并且待查看的资源已经载入游戏中.我希望的是不启动游戏,也能看到它的内存好做统计. 硬盘 由于unity中的资源压缩格式记录在 ...

  8. InnoDB Plugin文件格式(概述)

    本文将介绍InnoDB Plugin数据表格式的基本概念. 1. 配置参数innodb_file_format 这是一个很容易混淆的概念.目前,在InnoDB Plugin(1.0.6)配置文件中in ...

  9. easyUI之window

    window组件是一个可拖动.浮动的面板,用于显示信息.内容可用 href或ajax获取. window是一个显示窗口,同时也可以显示layout的功能(也就是创建复合的组合窗口),如 <div ...

  10. 通过JavaScript更新UpdatePanel备忘

    1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs ...