CF1866L.Lihmuf Balling

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

There will be NN turns numbered from 11 to NN . 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 MM . Before the game begins, Lihmuf must choose an integer KK satisfying 1KM1 \leq K \leq M . It is known that on the jj -th turn, Pak Chanek will choose the jj -th box, while Lihmuf will choose the yy -th box, with y=((j×K1)modN)+1y=((j \times K - 1) \bmod N) + 1 . Help Lihmuf choose the correct value of KK so that he will get as many balls as possible! If there are more than one possible values of KK that result in the maximum total balls, find the minimum such value of KK .

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 NN and MM ( 1N1091 \leq N \leq 10^9 ; 1M20001 \leq M \leq 2000 ) — the number of boxes and the maximum limit for the value of KK .

输出格式

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

输入输出样例

  • 输入#1

    3 1

    输出#1

    1
  • 输入#2

    5 4

    输出#2

    3

说明/提示

In the first example, if Lihmuf chooses K=1K=1 , the game will go as follows:

  1. Pak Chanek chooses the 11 -st box and gets 11 ball, then Lihmuf chooses the 11 -st box and gets 00 balls.
  2. Pak Chanek chooses the 22 -nd box and gets 22 balls, then Lihmuf chooses the 22 -nd box and gets 00 balls.
  3. Pak Chanek chooses the 33 -rd box and gets 33 balls, then Lihmuf chooses the 33 -rd box and gets 00 balls.

In total, Lihmuf gets 0+0+0=00+0+0=0 balls.

The maximum total balls that can be earned by Lihmuf is 00 because he can only choose K=1K=1 . Therefore, K=1K=1 is the minimum possible value of KK that results in the maximum total balls.

In the second example, if Lihmuf chooses K=3K=3 , the game will go as follows:

  1. Pak Chanek chooses the 11 -st box and gets 11 ball, then Lihmuf chooses the 33 -rd box and gets 33 balls.
  2. Pak Chanek chooses the 22 -nd box and gets 22 balls, then Lihmuf chooses the 11 -st box and gets 00 balls.
  3. Pak Chanek chooses the 33 -rd box and gets 00 balls, then Lihmuf chooses the 44 -th box and gets 44 balls.
  4. Pak Chanek chooses the 44 -th box and gets 00 balls, then Lihmuf chooses the 22 -nd box and gets 00 balls.
  5. Pak Chanek chooses the 55 -th box and gets 55 balls, then Lihmuf chooses the 55 -th box and gets 00 balls.

In total, Lihmuf gets 3+0+4+0+0=73+0+4+0+0=7 balls.

It can be obtained that 77 is the maximum total balls that can be earned by Lihmuf. The possible values of KK that result in 77 total balls are 33 and 44 . Therefore, K=3K=3 is the minimum possible value of KK that results in the maximum total balls.

首页