• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

  • 博客园
  • 联系
  • 订阅
  • 管理

View Post

组合——Program B

    CodeForces 478B

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




题目大意:将n个人分到m个队中,求队中成为朋友个数的最大值与最小值。

分析:此题是一个组合问题.










代码如下:

#include <iostream>
#include<cstdio>


 


using namespace std;
long long n, m;
long long cal(long long a)
{
  return a*(a-1)/2;
}
int main()
{
  while(scanf("%lld %lld",&n,&m)==2)
  {
    long long a=n/m;
    printf("%lld %lld\n", cal(a)*(m-n%m) + cal(a+1)*(n%m), cal(n-m+1));
  }
return 0;
}

 

posted on 2015-08-21 21:37  tony-cao  阅读(139)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3