B. Random Teams
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

题解:这个题首先能够通过公式推出1堆假设拆分成2堆。结果肯定是变小了。

所以要么其它堆都是1,一堆是n-m+1。要么均分。

结果非常大,要用long long。

#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; long long kmi,kma,n,m; int main()
{
scanf("%I64d%I64d",&n,&m);
long long b=n/m,c=n%m;
kmi=c*b*(b+1)/2+(m-c)*b*(b-1)/2;
kma=(n-m+1)*(n-m)/2;
printf("%I64d %I64d\n",kmi,kma);
return 0;
}

最新文章

  1. Graph database_neo4j 底层存储结构分析(5)
  2. STORM_0004_windows下zookeeper的伪集群的搭建
  3. Java中的大数处理类BigInteger和BigDecimar浅析
  4. [terry笔记]ArchiveLog归档日志激增解决思路
  5. 分享一下 aix安装python提示C编译器问题的办法
  6. Android ListView 全面优化
  7. Python使用mechanize模拟浏览器
  8. php的sendmail发件人邮箱设定
  9. js动态控制table的tr,td增加及删除
  10. 用maven搭建java ee项目
  11. SeleniumIDE_初识
  12. WPF-悬浮窗(类似于360)
  13. OpenCV分通道显示图片,灰度,融合,直方图,彩色直方图
  14. Git实战手册(三): stash解惑与妙用
  15. jquery 滑动取值
  16. Unity 3D连接MySQl数据库
  17. 594. Longest Harmonious Subsequence
  18. 创建django的8大步骤xxx.setAttribute(&#39;name&#39;, &#39;user&#39;); 添加属性和值 xxx.attr(&#39;name&#39;) 查看属性的值 $(xxx).addClass 添加样式 $().after() 添加在标签后面
  19. CSS总结:
  20. 记录表TABLE中 INDEX BY BINARY_INTEGER 的作用

热门文章

  1. iptables常用规则:屏蔽IP地址、禁用ping、协议设置、NAT与转发、负载平衡、自定义链
  2. 1.2 Activity
  3. String类和StringBuffer类
  4. noip模拟题题解集
  5. Sql Server数据批量更新
  6. VSCode调试配置
  7. server r2 系统更新文件清理
  8. Windows平台安装最新OpenCV-2.4.9,利用Eclipse、MinGW构建C++调用OpenCV开发环境
  9. Android获取 应用程序大小,数据大小,缓存大小
  10. jQuery中如何给动态添加的元素绑定事件