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
  1. 5 1
output
  1. 10 10
input
  1. 3 2
output
  1. 1 1
input
  1. 6 3
output
  1. 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个数尽量平均的时候,就得到最小值。

  1. #include<cstdio>
  2. #include<iostream>
  3.  
  4. #define LL long long
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. LL n,m;
  11. cin>>n>>m;
  12. LL tmax=,tmin=;
  13. tmax=m-+(n-m+)*(n-m+);
  14. LL a=n/m;
  15. LL b=n%m;
  16. int i=;
  17. tmin=b*(a+)*(a+)+(m-b)*(a*a);
  18.  
  19. cout<<(tmin-n)/<<" "<<(tmax-n)/<<endl;
  20. return ;
  21. }

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. Activity——思维导图

  2. Qt Creator调试

    与调试器交互的几种方法: 1.单行运行或者单指令运行 2.中断程序运行 3.设置断点 4.检查调用栈空间的内容 5.检查并修改局部或者全局变量 6.检查并修改被调试程序的寄存器和内存内容 7.检查装载 ...

  3. 【转】DBMS_STATS.GATHER_TABLE_STATS详解 2012-04-22 09:20:10

    [转]DBMS_STATS.GATHER_TABLE_STATS详解 2012-04-22 09:20:10 分类: Linux 由于Oracle的优化器是CBO,所以对象的统计数据对执行计划的生成至 ...

  4. python数据库连接池

    python数据库连接池 import psycopg2 import psycopg2.pool dbpool=psycopg2.pool.PersistentConnectionPool(1,1, ...

  5. 怎么用ABBYY打开PDF文档

    我们日常工作中接触的文档大多都是PDF格式的,这种格式的文件需要借助工具才能打开,大家最熟悉的无非就是Adobe了,但你知道吗?除了Adobe,OCR文字识别软件也可以打开PDF文档,比如ABBYY ...

  6. 在.net中悄悄执行dos命令,并获取执行的结果(转)

    一.怎样使dos命令悄悄执行,而不弹出控制台窗口? 1.需要执行带“/C”参数的“cmd.exe”命令,它表示执行完命令后立即退出控制台.2.设置startInfo.UseShellExecute = ...

  7. linux 下 nginx 启动服务器 80端口被占用问题

    把80端口占用的程序杀死 sudo fuser -k 80/tcp rm -fr 文件   ----删除文件及文加下的所有文件 echo > filename  ---清空文件的内容

  8. Oracle自增主键的添加[sequence]--表数据已存在

    --增加主键ID ); --设置sequence使ID自增 create sequence SEQ_ID minvalue maxvalue start ; --将id的值设置为sequence Up ...

  9. winform 承载 WCF 注意,可能不是工作在多线程模式下

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMo ...

  10. SPOJ #2 Prime Generator

    My first idea was Sieve of Eratosthenes, too. But obviously my coding was not optimal and it exceede ...