[Codeforces478B] 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 program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

输入格式 InputFormat

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.

输出格式 OutputFormat

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.

样例输入 SampleInput

599222887 298488

样例输出 SampleOutput

601178656545 179355218158217800

Codeforces 478B

代码 Code


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
ll i,j,t,n,m,l,r,k,z,y,x;
long long maxa,mina;
int main()
    maxa=(long long)(n-m+1)*(n-m)/2;
    mina=(long long)(n-m*t)*(t+1)*t/2+(m-n+m*t)*t*(t-1)/2;
    printf("%I64d %I64d\n",mina,maxa);
    return 0;