题库练习 Lihmuf Balling
← 上一题 下一题 →

A16260 | Lihmuf Balling

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

After working at a factory (Lihmuf Sorting), Lihmuf wants to play a game with his good friend, Pak Chanek. There are $N$ boxes numbered from $1$ to $N$ . The $i$ -th box contains $i$ balls. Pak Chanek and Lihmuf will play a game using those boxes.

There will be $N$ turns numbered from $1$ to $N$ . On each turn, Pak Chanek chooses one box and takes all balls from that box, then Lihmuf does the same thing for one box he chooses (it is possible that the two chosen boxes are the same).

Given an integer $M$ . Before the game begins, Lihmuf must choose an integer $K$ satisfying $1 \leq K \leq M$ . It is known that on the $j$ -th turn, Pak Chanek will choose the $j$ -th box, while Lihmuf will choose the $y$ -th box, with $y=((j \times K - 1) \bmod N) + 1$ . Help Lihmuf choose the correct value of $K$ so that he will get as many balls as possible! If there are more than one possible values of $K$ that result in the maximum total balls, find the minimum such value of $K$ .

Keep in mind that each box can be chosen more than once, but after a box is chosen for the first time, the box becomes empty.

输入格式

The only line contains two integers $N$ and $M$ ( $1 \leq N \leq 10^9$ ; $1 \leq M \leq 2000$ ) — the number of boxes and the maximum limit for the value of $K$ .

输出格式

An integer representing the value of $K$ that will make Lihmuf get as many balls as possible. If there are more than one possible value of $K$ that result in the maximum total balls, find the minimum such value of $K$ .

输入输出样例

输入 #1
3 1
输出 #1
1
输入 #2
5 4
输出 #2
3
C++ 编辑器
输入
输出