Count the minimum and maximum number of pairs that can be formed when people are split into teams as evenly as possible.
Random Teams
You are given people and need to split them into 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 is not divisible by , then exactly teams have size and the remaining teams have size .
Goal
Compute the smallest and largest possible number of same-team pairs over all valid balanced splits.
Input Format
The input contains two integers:
- — the number of people
- — 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
- The split must be balanced, so team sizes differ by at most $1$.
- Use 64-bit integers for the answer if needed.
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.