B - B

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

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 Input

Input
5 1
Output
10 10
Input
3 2
Output
1 1
Input
6 3
Output
3 6

Hint

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支队伍中去,每支队伍至少要有一个人,在一个队伍中的任意两个人都可以成为一对朋友,要你分配队伍,求出最少能够形成的朋友对数min,和最多能形成的队伍对数max.

思路:

当m=1的时候,也就是只有一支队伍,那么kmin=kmax=C(n,2);其余的情况求最大值的 时候我我们先把每个队伍分配一个人,然后把剩余的人全部分配到一个队伍,这样求得的为最大值,max=C(n-m+1,2),求最小值的时候,我们先把每个队伍都平均分配人数,剩余的人在任意选几个放一个人。

#include<iostream>
using namespace std;
int main()
{
long long minnum,maxnum,n,u,m,t,s,p;
cin>>n>>m;
if(m==)
{
minnum= maxnum=n*(n-)/;
cout<<minnum<<" "<<maxnum<<endl;
}
else
{
t=n/m;
p=n-t*m;
minnum=(m-p)*t*(t-)/+p*t*(t+)/;
u=n-m+;
maxnum=u*(u-)/;
cout<<minnum<<" "<<maxnum<<endl;
}
}

CodeForces 478B 第六周比赛B题的更多相关文章

  1. CodeForces 569A 第六周比赛C踢

    C - C Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. CodeForces 478B 第八次比赛 B题

    Description n participants of the competition were split into m teams in some manner so that each te ...

  3. LightOJ 1317 第六周比赛A题

    A - A Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Description Y ...

  4. HDU2669 第六周练习I题(扩展欧几里算法)

    第六周练习I题 I - 数论,线性方程 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  5. Codeforces 559A 第六周 O题

    Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...

  6. 第十六周oj刷题——Problem I: 改错题:类中私有成员的訪问

    Description 改错题: 设计一个日期类和时间类,并编写全局函数display用于显示日期和时间. 要求:display函数作为类外的普通函数,而不是成员函数 在主函数中调用display函数 ...

  7. 第十六周oj刷题——Problem E: B 构造函数和析构函数

    Description 在建立类对象时系统自己主动该类的构造函数完毕对象的初始化工作, 当类对象生命周期结束时,系统在释放对象空间之前自己主动调用析构函数. 此题要求: 依据主程序(main函数)和程 ...

  8. 暑假集训第一周比赛C题

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83146#problem/C C - 学 Crawling in process... C ...

  9. CodeForces 569A 第八次比赛 C题

    Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...

随机推荐

  1. FATE(完全背包)

    /* http://acm.hdu.edu.cn/showproblem.php?pid=2159 分析: 和普通的完全背包没有什么太大的区别 但是题目中给出了限制最多可杀s个怪 用二维数组dp[i] ...

  2. [tools] sublime 使用记录

    1. 目录下的文本搜索功能(自带) 1). 把文件夹拖到 sublime 上 2). 在 sublime 上展开要搜索的目录,右击,选择[find in folder] 2. sublime cons ...

  3. The game of life(生命游戏)新算法

    我写了一种常见的实现算法,和另一种新算法,即不是每次循环计算每个细胞的周围细胞数来产生下一时刻,而是每次每个产生状态变化的细胞主动通知周围的邻居,因此每个细胞增加一个用来记录邻居数的字段.由邻居数决定 ...

  4. hdu 4619 二分图最大匹配 ——最大独立集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 #include <cstdio> #include <cmath> # ...

  5. Threading Module源码概述(三)

    Threading中的Thread threading中一个关键的组件是threading.Thread. class Thread(_Verbose): __initialized = False ...

  6. HAProxy、Nginx 配置 HTTP/2 完整指南

    基于最近对HTTP/2的争论和它的优势,是时候升级底层架构了.这篇文章将会介绍如何在安装和配置HAProxy和Ngnix(使用ssl终端).为了简化流程,我建议你准备好使用Docker镜像. 如果你想 ...

  7. Intellij 部署maven项目

    一 部署Maven项目 1.下载和配置 (1)下载:maven.apache.org,点击download,下载apache-maven-3.3.9-bin.zip (2)配置环境变量: 环境变量包括 ...

  8. 来自投资银行的20个Java面试题

    问题一:在多线程环境中使用HashMap会有什么问题?在什么情况下使用get()方法会产生无限循环? HashMap本身没有什么问题,有没有问题取决于你是如何使用它的.比如,你在一个线程里初始化了一个 ...

  9. Git push本地代码到新建远程仓库

    快速搞定  1.git init #初始化本地仓库 2.git remote add origin https://git.oschina.net/redArmy/springboot-swagger ...

  10. Java基础知识强化之IO流笔记19:FileOutputStream的三个write方法

    1. FileOutputStream的三个write方法:  void write(byte[] buffer)           Writes the entire contents of th ...