CF1866L.Lihmuf Balling

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 1≤K≤M1 \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×K−1) mod N)+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.

在利姆夫分拣厂工作后,利姆夫想和他好朋友帕克·查内克玩一个游戏。共有 NN 个编号为 11 到 NN 的盒子,其中第 ii 个盒子包含 ii 个球。帕克·查内克和利姆夫将使用这些盒子进行游戏。

游戏共进行 NN 轮,轮次编号为 11 到 NN。在每一轮中,帕克·查内克先选择一个盒子,并取走该盒中的所有球;随后利姆夫也选择一个盒子(可与帕克·查内克所选相同),并取走该盒中的所有球。

给定一个整数 MM。在游戏开始前,利姆夫必须选定一个整数 KK,满足 1≤K≤M1 \leq K \leq M。已知:在第 jj 轮中,帕克·查内克必定选择第 jj 个盒子;而利姆夫则选择第 yy 个盒子,其中 y=((j×K−1) mod N)+1y = ((j \times K - 1) \bmod N) + 1。请帮助利姆夫选择合适的 KK 值,使得他获得的球总数尽可能多!若存在多个 KK 值能达成最大总球数,则选择其中最小的 KK。

注意:每个盒子可以被多次选择,但一旦某个盒子在某一轮中被首次选中,它就会变为空(即后续再被选中时不再提供球)。

输入格式

The only line contains two integers NN and MM (1≤N≤1091 \leq N \leq 10^9; 1≤M≤20001 \leq M \leq 2000) — the number of boxes and the maximum limit for the value of KK.

唯一的一行包含两个整数 NN 和 MM(1≤N≤1091 \leq N \leq 10^9;1≤M≤20001 \leq M \leq 2000)—— 分别表示盒子的数量以及 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.

一个整数,表示使 Lihmuf 获得球数最多的 KK 值。如果存在多个能获得最大总球数的 KK 值,则取其中最小的 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.

在第一个例子中,如果 Lihmuf 选择 K=1K=1,游戏过程如下:

  1. Pak Chanek 选择第 11 个盒子,获得 11 个球;随后 Lihmuf 选择第 11 个盒子,获得 00 个球。
  2. Pak Chanek 选择第 22 个盒子,获得 22 个球;随后 Lihmuf 选择第 22 个盒子,获得 00 个球。
  3. Pak Chanek 选择第 33 个盒子,获得 33 个球;随后 Lihmuf 选择第 33 个盒子,获得 00 个球。

总计,Lihmuf 获得 0+0+0=00+0+0=0 个球。

由于 Lihmuf 只能选择 K=1K=1,因此他能获得的最大总球数为 00。故 K=1K=1 是使得总球数达到最大值的最小可能的 KK 值。

在第二个例子中,如果 Lihmuf 选择 K=3K=3,游戏过程如下:

  1. Pak Chanek 选择第 11 个盒子,获得 11 个球;随后 Lihmuf 选择第 33 个盒子,获得 33 个球。
  2. Pak Chanek 选择第 22 个盒子,获得 22 个球;随后 Lihmuf 选择第 11 个盒子,获得 00 个球。
  3. Pak Chanek 选择第 33 个盒子,获得 00 个球;随后 Lihmuf 选择第 44 个盒子,获得 44 个球。
  4. Pak Chanek 选择第 44 个盒子,获得 00 个球;随后 Lihmuf 选择第 22 个盒子,获得 00 个球。
  5. Pak Chanek 选择第 55 个盒子,获得 55 个球;随后 Lihmuf 选择第 55 个盒子,获得 00 个球。

总计,Lihmuf 获得 3+0+4+0+0=73+0+4+0+0=7 个球。

可以验证,77 是 Lihmuf 能获得的最大总球数。使得总球数为 77 的可能的 KK 值有 33 和 44。因此,K=3K=3 是使得总球数达到最大值的最小可能的 KK 值。

输入解题思路,AI测评打分。不知道怎么写?

首页