http://codeforces.com/problemset/problem/478/B

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

题解:最小值:均分。最大值:(m-1)个team每个分1个participant,另一个team分(n-(m-1))个participant。

代码:

 #include <fstream>
#include <iostream> using namespace std; const int N=; inline __int64 num(int nn){
return (__int64)nn*(nn-)>>;
} int main(){
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
if(n==m) puts("0 0");
else{
int l=n/m,r=n%m;
printf("%I64d %I64d\n",num(l+)*r+num(l)*(m-r),num(n-m+));
}
return ;
}

cf478B-Random Teams 【排列组合】的更多相关文章

  1. cf478B Random Teams

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

  2. codeforces 478B Random Teams

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

  3. 学习sql中的排列组合,在园子里搜着看于是。。。

    学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...

  4. .NET平台开源项目速览(11)KwCombinatorics排列组合使用案例(1)

    今年上半年,我在KwCombinatorics系列文章中,重点介绍了KwCombinatorics组件的使用情况,其实这个组件我5年前就开始用了,非常方便,麻雀虽小五脏俱全.所以一直非常喜欢,才写了几 ...

  5. 【原创】开源.NET排列组合组件KwCombinatorics使用(三)——笛卡尔积组合

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  6. 【原创】开源.NET排列组合组件KwCombinatorics使用(二)——排列生成

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  7. 【原创】开源.NET排列组合组件KwCombinatorics使用(一)—组合生成

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  8. hdu1521 排列组合(指数型母函数)

    题意: 有n种物品,并且知道每种物品的数量ki.要求从中选出m件物品的排数.         (全题文末) 知识点: 普通母函数 指数型母函数:(用来求解多重集的排列问题) n个元素,其中a1,a2, ...

  9. [leetcode] 题型整理之排列组合

    一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...

随机推荐

  1. WINDOWS下kill进程的命令

    相信大家都有用命令行(CMD)解决问题的习惯,起码我感觉自己在处理Windows系统故障时越来越离不开Windows PE了,今天我想介绍两个很实用的命令:Tasklist与Tskill.命令:Tas ...

  2. 【转】VC 模式对话框和非模式对话框的创建,销毁和区别

    原文网址:http://blog.csdn.net/mycaibo/article/details/6002151 VC 模式对话框和非模式对话框的创建,销毁和区别   在WIN32中,模式对话框的创 ...

  3. linux的mysql

    mysql https://www.cnblogs.com/cnblogsfans/archive/2009/09/21/1570942.html https://blog.csdn.net/Smal ...

  4. python从网络时间服务器获取并打印当前时间以及pip安装ntplib的一次体验

    首先需要安装ntplib,科一通过pip安装. ubuntu下科一通过如下指令安装pip: $ sudo apt-get install python-pip 使用如下指令安装ntplib: $ su ...

  5. Hadoop的简单序列化框架

    Hadoop提供了一个加单的序列化框架API,用于集成各种序列化实现.该框架由Serialization实现. 其中Serialization是一个接口,使用抽象工厂的设计模式,提供了一系列和序列化相 ...

  6. 从汇编的角度看待const与#define

    先观察一下的代码: #include<stdio.h> int main(){ ; int y; int *pi=(int*)&i; *pi=; y=*pi; int tempi; ...

  7. Python库-re(正则表达式)

    re库是python的一个标准库,不需要自己用pip额外下载,直接调用即可. 下面介绍以下库中函数的作用. 1.re.compile(patter, flags=0) patter是一个正则表达式字符 ...

  8. HttpClient使用示例

    1)使用HttpClient发送GET请求 public class MainActivity extends Activity implements OnClickListener { privat ...

  9. java代码----------实现创建DataInputStream和DataOutputStream进行读写

    总结: 主要是 捕获异常 package com.a.b; import java.io.*; public class testData { public static void main(Stri ...

  10. Centos6-7安装Python3.5以及SSL的编译安装,识别https

    Python3中无法导入ssl模块的解决办法 如果你发现在python3脚本运行过程中发现涉及到ssl模块都无法运行的情况下.那么需要进行如下步骤 第一步: yum install openssl o ...