Under construction

Still being built. Things may change

Team Building

Time limit1sMemory limit1024 MB

Summary
Given n employees and team size k, find the fewest pairs that share a team on both days when each day is split into teams of k.
Level

Medium6 of 10

Topics
Math, Combinatorics
Solved
No attempts yet

Statement

The management of a large software company wants to run team building training for all nn employees. The training lasts two days. Each day, participants complete various tasks in teams of kk people. The number of employees is divisible by kk, so each day forms exactly n/kn / k teams of kk people. On both days the teams can be arbitrary, and the grouping on the second day may be completely independent of the first day.

The organizers are now making the schedule that assigns people to teams on each day. One goal of the training is for employees to work in a team with many different people, so the assignment has a natural requirement: the number of pairs of people who share a team on both days must be as small as possible.

Distributing people this way is harder than it looks. Find the minimum number of pairs of employees who end up in the same team on both days.

Input

The only line contains two integers nn and kk (4≤n≤1094 \leq n \leq 10^9, 2≤k<n2 \leq k < n, nn is divisible by kk), the number of employees in the company and the team size on both days of the training.

Output

Print the minimum number of pairs of employees who share a team on both days.

Hint

In the first sample, the people can be split on day one into (2, 4, 9), (1, 3, 8), (5, 6, 7), and on day two into (2, 5, 8), (3, 4, 7), (1, 6, 9). With this split, no pair of people shares a team on both days.

In the second sample, day one can be split into the teams (1, 3, 5, 7) and (2, 4, 6, 8), and day two into (1, 2, 7, 8) and (3, 4, 5, 6). Then four pairs (1 and 7, 2 and 8, 3 and 5, 4 and 6) share a team on both days. It can be shown that no better solution exists.

Examples2

  1. Example 1

    Input
    9 3
    
    Expected output
    0
    
  2. Example 2

    Input
    8 4
    
    Expected output
    4