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. ZENCART 二级 分类 展开

    zencart首页默认的是只显示一级分类,很多做仿牌外贸的朋友觉得只显示一级分类不好看,也不利于产品展示.怎么让zencart首页显示二级目录?下面分享给大家: 打开文件’includes/class ...

  2. [权威指南]学习笔记——第1、2章 MongoDB介绍和基础知识

    安装目录:C:\Program Files\MongoDB\Server\3.2 Bin:..\..\Program Files\MongoDB\Server\3.2\bin 启动命令:mongod ...

  3. git常用命令和github

    工作区:就是你的工作目录 暂存区:它像个缓存区域,临时保存你的改动 版本区:就是你的git仓库 HEAD:相当于一个指针,指向你最近一次提交后的结果 git status 查看状态 git add . ...

  4. golang 自定义time.Time json输出格式

    工作中使用golang时,遇到了一个问题.声明的struct含time.Time类型.使用json格式化struct时,time.Time被格式化成”2006-01-02T15:04:05.99999 ...

  5. csr_matrix参数解析

    压缩稀疏矩阵构造时的参数从官网看不明白,参考如下: >>> indptr = np.array([0, 2, 3, 6]) >>> indices = np.arr ...

  6. UVA - 808 Bee Breeding (建立坐标系&找规律)

    题目: 输入两个格子的编号a和b(a,b≤10000),求最短距离.例如,19和30的距离为5(一条最短路是19-7-6-5-15-30). 思路: 如图建立坐标系,然后看两个点的向量如果位于二四象限 ...

  7. Ztree加载完成后显示勾选节点

    ①前言:这个在度娘上没有搜到解决的办法,于是自己查看了ztree的API,发现其实还是比较简单的.做个笔记以备不时之需. ②需求: 像下图一样,在加载完成之后就显示需要勾选的项. ③解决方案: 首先页 ...

  8. WebStorm 格式化代码快捷键

    原文链接:https://kaifazhinan.com/webstorm-formatting-code-shortcuts/ 现在平时都是使用 VS Code 作为日常开发工具,偶尔会打开 Web ...

  9. eclipse自动换行

    Eclipse是一款非常优秀的IDE,但是不能自动换行,需要安装一个插件完成这个功能. 安装办法有两种: 1.在线安装. 选择help-->install new software,点击Add, ...

  10. CentOS \Linux文件权限详解

    文件和目录权限概述 在linux中的每一个文件或目录都包含有访问权限,这些访问权限决定了谁能访问和如何访问这些文件和目录. 通过设定权限可以从以下三种访问方式限制访问权限:只允许用户自己访问:允许一个 ...