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

n个人分到m组里,每一组对于答案的贡献是人数排列组合,就是n*(n-1)/2。求最大值和最小值

显然前面取m-1组的1最后一组最大的方案是答案最大

平均分的方案是答案最小

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
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;
}
LL a,b,c,d,e;
int main()
{
a=read();b=read();
c=(a-b+)*(a-b)/;
d=(a-b*(a/b));
e=(d)*(a/b+)*(a/b)/+(b-d)*(a/b)*(a/b-)/;
printf("%lld %lld\n",e,c);
}

cf478B

cf478B Random Teams的更多相关文章

  1. codeforces 478B Random Teams

    codeforces   478B  Random Teams  解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...

  2. B. Random Teams(Codeforces Round 273)

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. 【CODEFORCES】 B. Random Teams

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #273 (Div. 2)-B. Random Teams

    http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...

  5. Codeforces Round #273 (Div. 2) B . Random Teams 贪心

    B. Random Teams   n participants of the competition were split into m teams in some manner so that e ...

  6. CF478 B. Random Teams 组合数学 简单题

    n participants of the competition were split into m teams in some manner so that each team has at le ...

  7. Random Teams

    n participants of the competition were split into m teams in some manner so that each team has at le ...

  8. codeforces 478B Random Teams 解题报告

    题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...

  9. cf478B-Random Teams 【排列组合】

    http://codeforces.com/problemset/problem/478/B B. Random Teams   n participants of the competition w ...

随机推荐

  1. kibana 访问IP分布图

  2. c++ 02

    一.堆内存的动态分配与释放 malloc/calloc/realloc/free new/delete:详见memory.cpp 1.通过new运算符分配单个变量 数据类型* 指针变量 = new 数 ...

  3. 使用WCF实现SOA面向服务编程—— 架构设计

    原文地址:http://www.cnblogs.com/leslies2/archive/2011/03/29/1997889.html SOA本身就是一种面向企业级服务的系统架构,简单来说,SOA就 ...

  4. poj 2481 Cows(数状数组 或 线段树)

    题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [ ...

  5. 利用智能手机(Android)追踪一块磁铁(一)

    之前看到一个外国人用iPhone做了一个追踪磁铁的Demo感觉不错(参考视频:http://v.youku.com/v_show/id_XODM2MjczNzE2.html),然后我就参考做了一个An ...

  6. Tomcat 常见问题篇

    Tomcat 常见问题一.Tomcat常见问题 1.Tomcat web容器出现故障时,我们通过Tomcat自带的logs查看原因,以下错误提示都是源于logs 2.Connection refuse ...

  7. MATLAB快速注释方法

    觉得有用,未免以后忘记,收藏了.原文来自:http://i.azpala.com/2008/09/18/matlab-multi-line-comment/ A. %{ 若干语句 %} B. 多行注释 ...

  8. android——仿网易今日头条等自定义频道listview 或者grideview等item上移到另一个view中

    转载请注明出处: www.cnblogs.com/shoneworn 我这里只是简单的用了两个listview来实现的,先上效果图.比较粗糙.预留了自定义的空间. 思路: 从上图应该可以看的出来.就是 ...

  9. 解决jquery和其他库的冲突

    一.jquery在其他库之后导入 (1)jQuery.noConflict();  //将变量的$控制权转交给其他库.          jQuery(function(){             ...

  10. Know Thy Complexities!

    http://bigocheatsheet.com/ Hi there!  This webpage covers the space and time Big-O complexities of c ...