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

解题思路:
题意:
n个人分到m支队伍里,在同一个队伍的任意两人将成为一对朋友,问能形成最少多少对朋友,最多多少对朋友。每支队伍至少要有一个人。
分析:
假设某只队伍有k个人, 那么形成的朋友对数有C(k, 2)对。
最大的对数:将所有人尽可能的集中在一只队伍里, 让尽可能多的人相互认识
最小的对数:将所有人尽可能的分开,即平分
程序代码:
#include <cstdio>
using namespace std;
int main()
{
long long n,m;
while(scanf("%lld%lld",&n,&m)!=EOF)
{
long long a=n/m;
long long b=n%m;
long long mi=b*a*(a+)/+(m-b)*a*(a-)/;
long long ma=(n-m+)*(n-m)/;
printf("%lld %lld\n",mi,ma);
}
return ;
}

ACM第六周竞赛题目——B CodeForces 478B的更多相关文章

  1. ACM第六周竞赛题目——A LightOJ 1317

    A - A Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  2. 1903021116—吉琛—Java第六周作业—类的定义

    项目 内容 课程班级博客链接 19信计班 这个作业要求链接 第六周作业链接 java面向对象的概念和定义 博客名称 学号-姓名-Java第六周作业-题目自拟 要求 每道题要有题目,代码(使用插入代码, ...

  3. 20145337 《Java程序设计》第六周学习总结

    20145337 <Java程序设计>第六周学习总结 教材学习内容总结 输入\输出 InputStream与OutputStream 从应用程序角度来看,如果要将数据从来源取出,可以使用输 ...

  4. 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)

    第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...

  5. 《ACM国际大学生程序设计竞赛题解Ⅰ》——基础编程题

    这个专栏开始介绍一些<ACM国际大学生程序设计竞赛题解>上的竞赛题目,读者可以配合zju/poj/uva的在线测评系统提交代码(今天zoj貌似崩了). 其实看书名也能看出来这本书的思路,就 ...

  6. 201521123061 《Java程序设计》第六周学习总结

    201521123061 <Java程序设计>第六周学习总结 ***代码阅读:Child压缩包内 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核 ...

  7. 201521123038 《Java程序设计》 第六周学习总结

    201521123038 <Java程序设计> 第六周学习总结 1. 本周学习总结 2. 书面作业 1.clone方法 1.1 Object对象中的 clone 方法是被protected ...

  8. 201521123122 《java程序设计》 第六周实验总结

    201521123122 <java程序设计>第六周实验总结 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想 ...

  9. 201621123040《Java程序设计》第六周学习总结

    1.本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结 2.书面作业 2.1clone方法 2.1.1在te ...

随机推荐

  1. C#日期转换类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Te ...

  2. 如何在安卓/data(而不是/data/data)目录下进行文件的读写操作

    分析:Android默认是无法直接操作/data目录的,只能读写程序自己的私有目录,也就是/data/data/package name/下,默认只能操作这个目录下的文件,也就是我们想直接读写/dat ...

  3. 创建 window service 定时任务

    参考文章:http://www.cnblogs.com/jack-liang/archive/2011/05/20/2051743.html 前段时间做过一个项目,前端系统提供添加定时任务,后端系统要 ...

  4. 关于UNION和UNION ALL的区别

    今天在运行程序的时候发现个问题,就是计算和的时候两条数据一样的话自动去除重复的,可是我这个程序需要重复的数据也算进来呀,然后就找原因,最后在sql语句中找到了是union和union all的问题,简 ...

  5. 比较两份文件的异同-beyond compare

    比较两份文件的异同-beyond compare 今天又学到一个知识,比较两次文件的 异同.  哈哈 谢谢领导

  6. C#快速导入海量XML数据至SQL Server数据库

    #region 将Xml中的数据读到Dataset中,然后用SqlBulkCopy类把数据copy到目的表中using (XmlTextReader xmlReader = new XmlTextRe ...

  7. C#遍历所有的Textbox控件并赋值为String.Empty

    foreach (Control control in this.Controls) { if (control.GetType().Name.Equals("TextBox")) ...

  8. Smart Client Software Factory安装

    首先要安装 Visual Studio 2010 SDK 不然无法安装 Smart Client Software Factory 2010 然后按顺序安装 GAX 2010 http://visua ...

  9. mysql,left join on

    转自http://www.oschina.net/question/89964_65912 觉得很有帮助,用来学习. 即使你认为自己已对 MySQL 的 LEFT JOIN 理解深刻,但我敢打赌,这篇 ...

  10. [原创]用python写了一个简单的markdown编辑器

    以前我常用openoffice记录东西,最喜欢它的当然是在linux上能用了,还有里面的公式输入,前几天才了解markdown这个东东,初步了解发现它正是我需要的东西,可以用它随心所欲地记录些东西,而 ...