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;
}

【CODEFORCES】 B. Random Teams的更多相关文章

  1. 【CF1133E】K Balanced Teams(动态规划,单调队列)

    [CF1133E]K Balanced Teams(动态规划,单调队列) 题面 CF 让你把一堆数选一些出来分成不超过\(K\)组,每一组里面的最大值和最小值之差不超过\(5\),求最多有多少个人元素 ...

  2. 【Codeforces】Round #491 (Div. 2) 总结

    [Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...

  3. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  4. 【CodeForces】601 D. Acyclic Organic Compounds

    [题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...

  5. 【Codeforces】849D. Rooter's Song

    [算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...

  6. 【CodeForces】983 E. NN country 树上倍增+二维数点

    [题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...

  7. 【CodeForces】925 C.Big Secret 异或

    [题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...

  8. 【CodeForces】700 D. Huffman Coding on Segment 哈夫曼树+莫队+分块

    [题目]D. Huffman Coding on Segment [题意]给定n个数字,m次询问区间[l,r]的数字的哈夫曼编码总长.1<=n,m,ai<=10^5. [算法]哈夫曼树+莫 ...

  9. 【CodeForces】906 D. Power Tower 扩展欧拉定理

    [题目]D. Power Tower [题意]给定长度为n的正整数序列和模数m,q次询问区间[l,r]累乘幂%m的答案.n,q<=10^5,m,ai<=10^9. [算法]扩展欧拉定理 [ ...

随机推荐

  1. IE首页被篡改(手动修复)

    所谓手动修复,即以不变应万变,修改注册表,其实工具软件也只是帮你代工而已. win + R 打开 “运行”,键入 “regedit.exe” 打开注册表编辑器,在 路径 HKEY_LOCAL_MACH ...

  2. spring 多个数据库之间切换

    多数据源问题很常见,例如读写分离数据库配置. 原来的项目出现了新需求,局方要求新增某服务器用以提供某代码,涉及到多数据源的问题. 研究成果如下: 1.首先配置多个datasource [html] v ...

  3. java @override 报错处理

    转载自:http://blog.sina.com.cn/s/blog_9c7605530101kl9r.html 一.java @override 报错处理 做项目的时候,同事那边电脑上编译通过的ja ...

  4. ExtFormReturn,ext

    package cn.edu.hbcf.common.vo; public class ExtFormReturn { /** * 是否成功 */ private boolean success; / ...

  5. bootstrap table 服务器端分页--ashx+ajax

    1.准备静态页面 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-T ...

  6. cocos2dx 富文本框,支持换行,支持神情(支持汉字截断无乱码)

    cocos2dx 富文本框,支持换行,支持表情(支持汉字截断无乱码) 小工在做了一个游戏聊天功能,里面用到插入表情的富文本和换行的问题: 先看效果,不是你要的效果,可return:(截图由于:输入的问 ...

  7. 详解 SWT 中的 Browser.setUrl(String url, String postData, String[] headers) 的用法

    http://hi.baidu.com/matrix286/item/b9e88b28b90707c9ddf69a6e ———————————————————————————————————————— ...

  8. ABP中连接已有数据库执行Sql或存储过程

    一:在EntityFramework项目中创建类如:ZSWDbContext. public class ZSWDbContext : AbpDbContext { public ZSWDbConte ...

  9. 【BZOJ】2017: [Usaco2009 Nov]硬币游戏(dp+神题+博弈论)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2017 这题太神了,我想了一个中午啊 原来是看错题一直没理解题解说的,一直以为题解是错的QAQ “开始 ...

  10. ytu 2231: 交集问题(线性表)(数据结构,链表练习)

    2231: 交集问题(线性表) Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 6  Solved: 3[Submit][Status][Web Boar ...