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

代码

Codeforces Round #273 (Div. 2) B . Random Teams 贪心的更多相关文章

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

  2. 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations

    题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...

  3. Codeforces Round #273 (Div. 2)

    A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...

  4. Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心

    A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. codeforces Codeforces Round #273 (Div. 2) 478B

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

  6. Codeforces Round #247 (Div. 2) D. Random Task

    D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #273 (Div. 2)-C. Table Decorations

    http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...

  8. Codeforces Round #273 (Div. 2)-A. Initial Bet

    http://codeforces.com/contest/478/problem/A A. Initial Bet time limit per test 1 second memory limit ...

  9. Codeforces Round #246 (Div. 2) A. Choosing Teams

    给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...

随机推荐

  1. windows2008 rs+sql 2008 下配置站点权限

    几点注意 Windows 2008 iis7.5  1 建立应用程序池 2 文件目录的权限加上 IIS AppPool\应用程序池名称 (找不到直接录入) 3 文件目录要给 IUser权限,不然出错. ...

  2. C/c++中 数组全局变量的定义声明 与 引用声明

    数组声明一次,所有的  定义声明  有切仅有一次! 别人遇到的问题如下: 在声明定义时,定义数组如下: int G_glob[100]; 在其他文件引用时声明如下: int *G_glob; 这样的操 ...

  3. 【alert(1) to win】不完全攻略

    alert(1) to win 一个练习XSS的平台,地址:https://alf.nu/alert1 Warmup 给出了一段JavaScript代码 function escape(s) { re ...

  4. (转) 淘淘商城系列——Redis五种数据类型介绍

    http://blog.csdn.net/yerenyuan_pku/article/details/72855562 Redis支持五种数据类型:string(字符串),hash(哈希),list( ...

  5. PHP封装数据库

    (1)按照步骤封装数据库 ①引入抽象类和抽象方法,即引入模板: ②继承抽象类,注意参数(规定几个就传入几个): ③逐个写入抽象方法,必须一一对应:(抽象方法必须一一引入,否则会报错-->有个抽象 ...

  6. jenkins自动部署测试环境

    构建脚本如下: echo "当前目录":$(pwd)echo "当前时间":$(date +%Y-%m-%d_%H:%M)find ./ -type f -na ...

  7. mybatis中resultMap引发的吐血bug

    简单的讲: 问题背景:如果在写mybatis中的resultMap时,不下心将resultMapde id写成映射接口的名字,会发生什么? 结论:单元测试进度条卡住但不报错, Tomcat运行不报错, ...

  8. C++ volatile关键字(转)

    文章来源: http://hedengcheng.com/?p=725 https://www.cnblogs.com/god-of-death/p/7852394.html 1.基本概念 volat ...

  9. Re0:DP学习之路 01背包如何打印路径?

    伪代码 用二维数组记录,如果出现可以转移的dp那么记录bk[当前体积][装的物品]=1 输出的时候倒推,如果存在连通的边那么输出并且总共的体积减去输出的体积 代码(uva-624,目前wa不明所以,网 ...

  10. Python学习-变量

    什么是变量? 概念:变量就是会变化的量,主要是“变”与“量”二字.变即是“变化”. 特点:与其他编程语言相同,变量是最基本的存储单位,是用来存放数据的容器.可以引用一个具体的数值,进而直接去改变这个引 ...