CodeForces 478B

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

题目大意:将n个人分到m个队中,求队中成为朋友个数的最大值与最小值。

分析:此题是一个组合问题.

代码如下:

#include <iostream>
#include<cstdio>



using namespace std;
long long n, m;
long long cal(long long a)
{
  return a*(a-1)/2;
}
int main()
{
  while(scanf("%lld %lld",&n,&m)==2)
  {
    long long a=n/m;
    printf("%lld %lld\n", cal(a)*(m-n%m) + cal(a+1)*(n%m), cal(n-m+1));
  }
return 0;
}

 

最新文章

  1. Would Your Work Habits Change if You Were Paid by the Job?
  2. Redis 无法正常关闭服务
  3. 【Java每日一题】20161107
  4. HT图形组件设计之道(四)
  5. HTML5摇一摇
  6. CSS定位属性Position详解
  7. 从客户端(Content=&quot;&lt;p&gt;666&lt;/p&gt;&quot;)中检测到有潜在危险的 Request.Form 值。
  8. vs中web配置可浏览json数据文件
  9. P3928 SAC E#1 - 一道简单题 Sequence2
  10. [转]FFMpeg框架代码阅读
  11. ES6 中的 iterator
  12. Spring Aop底层原理详解
  13. 解决No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource.跨域问题(后台(java)解决方法)
  14. [原创]K8Cscan插件之多种方式系统版本探测
  15. 二十四、Linux 进程与信号---wait 函数
  16. redis 五种数据类型
  17. Android 监听 ScrollView 滑动到最底部。
  18. Struts2学习(三)———— 输入校验和拦截器
  19. Pandas简易入门(一)
  20. TP图片上传

热门文章

  1. oracle对象类型
  2. Tomcat:IOException while loading persisted sessions: java.io.EOFException解决手记
  3. valueForKeyPath的妙用(转)
  4. 20160805_CentOS6_键盘快捷键
  5. js中正则表达式 书写方法
  6. selenium 加载RemoteDriver浏览器驱动
  7. quartz定时任务框架的使用
  8. WLAN频段介绍-04
  9. IE5,IE6,IE7,IE8的css兼容性列表[转自MSDN]
  10. Simple Data