405292: GYM101875 A Nicoleta and the circle of kids

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Nicoleta and the circle of kidstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Nicoleta is a happy kid, he goes every day to school and is always complaining about waking up early and having to complete his homework assignments. His favorite professor, Afonsox, is very funny and created a new challenge for him.

Even though Nicoleta is just a kid, Afonsox introduced him to the world of graph theory. Nicoleta is amazed, he is very obsessed with this graph that Afonsox decided to call K-round graph. A K-round graph with N vertices is a graph where every vertex u, numbered from 0 to N - 1, has an edge to vertices (u + 1)%N, ..., (u + K)%N. Here a%b is the operator that gives the remainder of the integer division of a by b. Also, an edge between vertices u and (u + i)%N has value i.

Nicoleta likes this graph because if you draw it, it looks like a circle of kids, where each kid has K arms with different lengths with which they can reach the K next kids, like the picture below, which he drew in his notebook. Imagining this makes Nicoleta smile.

Figure: A 2-round graph with 4 vertices drawn by Nicoleta.

The challenge Afonsox has proposed to Nicoleta is for him to find the sum of all the values of the edges in the maximum spanning tree of a given K-round graph. A maximum spanning tree of a graph is composed of all of its vertices and a subset of edges such that there is one and only one path from one vertex to another and the sum of the values of the edges is maximal. Can you help Nicoleta finding the answer to Afonsox challenge?

Input

The input consists of a single line containing two integers N and K (1 ≤ K < N ≤ 109), indicating the number of vertices in the graph and the number of outgoing edges from every vertex.

Output

Output a single integer - the sum of the values of the edges in the maximum spanning tree of the K-round graph.

ExamplesInput
3 2
Output
4
Input
6 2
Output
9

Source/Category

加入题单

算法标签: