Skip to main content
Back to problems
Codeforces
Medium
Math
Combinatorics
Random Teams

Count the minimum and maximum number of pairs that can be formed when nn people are split into kk teams as evenly as possible.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Random Teams

You are given nn people and need to split them into kk teams. The teams should be as balanced as possible: some teams may have one extra person, but the team sizes can differ by at most $1$.

After the teams are formed, consider how many pairs of people can be on the same team.

Your task is to determine:

  • the minimum possible number of same-team pairs,
  • the maximum possible number of same-team pairs.

A pair means two distinct people belonging to the same team.

Explanation of the team sizes

If nn is not divisible by kk, then exactly nmodkn \bmod k teams have size n/k+1\lfloor n/k \rfloor + 1 and the remaining teams have size n/k\lfloor n/k \rfloor.

Goal

Compute the smallest and largest possible number of same-team pairs over all valid balanced splits.

Input Format

The input contains two integers:

  • nn — the number of people
  • kk — the number of teams

Output Format

Print two integers:

  • the minimum possible number of same-team pairs
  • the maximum possible number of same-team pairs

Constraints

  • 1kn1 \le k \le n
  • The split must be balanced, so team sizes differ by at most $1$.
  • Use 64-bit integers for the answer if needed.
Examples
Sample cases returned by the problem API.

Example 1

Input

7 3

Output

5 6

Explanation

A balanced split is sizes 3, 2, and 2. The minimum number of pairs is obtained by keeping teams as even as possible: C(3,2)+C(2,2)+C(2,2)=3+1+1=5. The maximum is 6.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.