B. Random Teams
 

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
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.

 题意:给你n,m,将n个人分配到m个小组,每组至少一个人,组内成员会成为朋友,问你在所有可行的分配方法中最少,最多有多少对朋友

题解:显然组成员尽量大,是最多,最分散是最少

///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define inf 1000000007
#define mod 1000000007
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//************************************************
const int maxn=+; ll n,m,ans1,ans2;
int main(){
scanf("%I64d%I64d",&n,&m);
ans1=n-(m-);
ans1=(ans1)*(ans1-)/;
ans2=n/m;
if(n%m)ans2++;
ans2=(ans2)*(ans2-)/;
ans2= ans2*(n%m)+(m-(n%m))*(n/m)*(n/m-)/;
cout<<ans2<<" "<<ans1<<endl;
return ;
}

代码

最新文章

  1. 自定义委托类型 - .Net自带委托类型
  2. Java面试(1)-- Java逻辑运算符
  3. switch2osm使用open street map离线地图中文乱码方框解决办法
  4. android-解决EditText的inputType为Password时, 字体不一致的问题
  5. 配置Android开发环境
  6. 解决Linux文档显示中文乱码问题以及编码转换
  7. Android提高第十一篇之模拟信号示波器
  8. js模板引擎--artTemplate
  9. Java heap space
  10. 讲究门面的Request
  11. Python之深浅拷贝
  12. SQL server 统计数据库表数量和列出所有表名称
  13. python 中list的深拷贝和浅拷贝
  14. laravel Schema 查看索引是否存在
  15. 微信小程序制作家庭记账本之四
  16. python ---12 生成器 推导式
  17. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题
  18. HTML5标签embed详解
  19. 奇偶数判断2(if else+switch语句)
  20. java 修饰符总结

热门文章

  1. navicat创建存储过程报错
  2. HDU_1011_Starship Troopers_树型dp
  3. Masonry 原理与使用说明
  4. vue基础---实例
  5. 全局唯一的支付和订单id生成算法
  6. [转]SAS盘和SATA盘之间的区别
  7. 关押罪犯 - 并查集&amp;优先队列
  8. NOIp2017——追求那些我一直追求的
  9. Q-criterion- definition and post-processing
  10. 腾讯云,体验域名注册解析与SSL证书