问题 B: Cake 2

内存限制:1024 MB 时间限制:1 S
题面:Markdown 评测方式:文本比较 上传者:
提交:4 通过:3

题目描述

Grammy bought a big cake. The shape of the cake is a regular polygon. That is, a convex polygon whose all interior angles are equal and all edges are equal. Grammy wants to cut the cake into a pretty pattern and share the cake with her friends. She indexed the vertices $0$ through $n-1$ in counterclockwise order and chooses an integer $k$. After that, she cuts the cake through $n$ straight lines connecting vertex $i$ and vertex $(i+k)\bmod n$ for each $i$. Grammy wants to know the number of pieces after cutting the cake. Please calculate it for her.

输入格式

The only line contains $2$ integers $n,k$ ($4\leq n \leq 10^6, 2\leq k \leq n-2$), denoting the number of sides of the regular polygon and the integer chosen by Grammy.

输出格式

Output a single integer in a line, denoting the number of pieces after cutting the cake.

输入样例 复制

6 2

输出样例 复制

13

数据范围与提示

For the sample test case, the final cake is shown below:  ![](https://uploadfiles.nowcoder.com/images/20240801/0_1722457118119/4A47A0DB6E60853DEDFCFDF08A5CA249)