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

input

3 2

output

1 1

input

6 3

output

3 6

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.

其实题目可以转化为

A1+A2+...+An=n;

求C(A1,2)+C(A2,2)+C(A3,2)+...+C(An,2)的最大最小值

利用高中学过的基本不等式就可以了

其实 好像用常识就可以解题了,,,我认为。。。

#include<iostream>
using namespace std;
long long int fun(long long int i){
    if(i<2)return 0;
    if(i%2==1)return (i-1)/2*i;
    return i/2*(i-1);
}
int main(){
    long long int n,m;
    while(cin>>n>>m){
        long long int t=n/m;
        long long int t1=n%m;
        long long int mi;
        mi=fun(t+1)*t1+fun(t)*(m-t1);
       long long int ma=fun(n-m+1);
        cout<<mi<<" "<<ma<<endl;
    }
return 0;
}

时间: 2024-11-04 16:08:38

Random Teams的相关文章

Codeforces Round #273 (Div. 2) B . Random Teams 贪心

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 progra

Random Teams(Codeforces Round 273)

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 th

Codeforces 478B.Random Teams

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 part

Codeforces Round 273 Random Teams 解题心得

原题: 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 progra

cf478B-Random Teams 【排列组合】

http://codeforces.com/problemset/problem/478/B 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

cf Round#273 Div.2

题目链接,点击一下 Round#273 Div.2 ================== problem A Initial Bet ================== 很简单,打了两三场的cf第一次在10分钟内过题 判平均数,且注意b为正 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int res = 0,n; 6 for(int i = 0; i < 5; i++) 7 { 8 cin>>

numpy的random模块

[说明] 翻译自官网的文档. 随机抽样 (numpy.random) 简单的随机数据 rand(d0, d1, ..., dn) 随机值 >>> np.random.rand(3,2) array([[ 0.14022471, 0.96360618], #random [ 0.37601032, 0.25528411], #random [ 0.49313049, 0.94909878]]) #random randn(d0, d1, ..., dn) 返回一个样本,具有标准正态分布.

[TypeScript] Create random integers in a given range

Learn how to create random integers using JavaScript / TypeScript. /** * Returns a random int between * @param start inclusive * @param before exclusive */ export function randomInt(start: number, before: number) { return start + Math.floor(Math.rand

java中Random随机种子使用

在java中,通过Random生成随机数时,如果设置随机种子,则相同的种子,产生的随机数相同.若不设置则每次随机的不同. Random rnd = new Random(); rnd.setSeed(10);//用于设置种子. rnd.nextInt();// 用于产生随机数. rnd.nextInt(10); // 产生(0-9)数字.