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