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 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≤K≤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×K−1)modN)+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.
在利姆夫分拣厂工作后,利姆夫想和他好朋友帕克·查内克玩一个游戏。共有 N 个编号为 1 到 N 的盒子,其中第 i 个盒子包含 i 个球。帕克·查内克和利姆夫将使用这些盒子进行游戏。
游戏共进行 N 轮,轮次编号为 1 到 N。在每一轮中,帕克·查内克先选择一个盒子,并取走该盒中的所有球;随后利姆夫也选择一个盒子(可与帕克·查内克所选相同),并取走该盒中的所有球。
给定一个整数 M。在游戏开始前,利姆夫必须选定一个整数 K,满足 1≤K≤M。已知:在第 j 轮中,帕克·查内克必定选择第 j 个盒子;而利姆夫则选择第 y 个盒子,其中 y=((j×K−1)modN)+1。请帮助利姆夫选择合适的 K 值,使得他获得的球总数尽可能多!若存在多个 K 值能达成最大总球数,则选择其中最小的 K。
注意:每个盒子可以被多次选择,但一旦某个盒子在某一轮中被首次选中,它就会变为空(即后续再被选中时不再提供球)。
输入格式
The only line contains two integers N and M (1≤N≤109; 1≤M≤2000) — the number of boxes and the maximum limit for the value of K.
唯一的一行包含两个整数 N 和 M(1≤N≤109;1≤M≤2000)—— 分别表示盒子的数量以及 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.
一个整数,表示使 Lihmuf 获得球数最多的 K 值。如果存在多个能获得最大总球数的 K 值,则取其中最小的 K 值。
输入输出样例
输入#1
3 1
输出#1
1
输入#2
5 4
输出#2
3
说明/提示
In the first example, if Lihmuf chooses K=1, the game will go as follows:
- Pak Chanek chooses the 1-st box and gets 1 ball, then Lihmuf chooses the 1-st box and gets 0 balls.
- Pak Chanek chooses the 2-nd box and gets 2 balls, then Lihmuf chooses the 2-nd box and gets 0 balls.
- Pak Chanek chooses the 3-rd box and gets 3 balls, then Lihmuf chooses the 3-rd box and gets 0 balls.
In total, Lihmuf gets 0+0+0=0 balls.
The maximum total balls that can be earned by Lihmuf is 0 because he can only choose K=1. Therefore, K=1 is the minimum possible value of K that results in the maximum total balls.
In the second example, if Lihmuf chooses K=3, the game will go as follows:
- Pak Chanek chooses the 1-st box and gets 1 ball, then Lihmuf chooses the 3-rd box and gets 3 balls.
- Pak Chanek chooses the 2-nd box and gets 2 balls, then Lihmuf chooses the 1-st box and gets 0 balls.
- Pak Chanek chooses the 3-rd box and gets 0 balls, then Lihmuf chooses the 4-th box and gets 4 balls.
- Pak Chanek chooses the 4-th box and gets 0 balls, then Lihmuf chooses the 2-nd box and gets 0 balls.
- Pak Chanek chooses the 5-th box and gets 5 balls, then Lihmuf chooses the 5-th box and gets 0 balls.
In total, Lihmuf gets 3+0+4+0+0=7 balls.
It can be obtained that 7 is the maximum total balls that can be earned by Lihmuf. The possible values of K that result in 7 total balls are 3 and 4. Therefore, K=3 is the minimum possible value of K that results in the maximum total balls.
在第一个例子中,如果 Lihmuf 选择 K=1,游戏过程如下:
- Pak Chanek 选择第 1 个盒子,获得 1 个球;随后 Lihmuf 选择第 1 个盒子,获得 0 个球。
- Pak Chanek 选择第 2 个盒子,获得 2 个球;随后 Lihmuf 选择第 2 个盒子,获得 0 个球。
- Pak Chanek 选择第 3 个盒子,获得 3 个球;随后 Lihmuf 选择第 3 个盒子,获得 0 个球。
总计,Lihmuf 获得 0+0+0=0 个球。
由于 Lihmuf 只能选择 K=1,因此他能获得的最大总球数为 0。故 K=1 是使得总球数达到最大值的最小可能的 K 值。
在第二个例子中,如果 Lihmuf 选择 K=3,游戏过程如下:
- Pak Chanek 选择第 1 个盒子,获得 1 个球;随后 Lihmuf 选择第 3 个盒子,获得 3 个球。
- Pak Chanek 选择第 2 个盒子,获得 2 个球;随后 Lihmuf 选择第 1 个盒子,获得 0 个球。
- Pak Chanek 选择第 3 个盒子,获得 0 个球;随后 Lihmuf 选择第 4 个盒子,获得 4 个球。
- Pak Chanek 选择第 4 个盒子,获得 0 个球;随后 Lihmuf 选择第 2 个盒子,获得 0 个球。
- Pak Chanek 选择第 5 个盒子,获得 5 个球;随后 Lihmuf 选择第 5 个盒子,获得 0 个球。
总计,Lihmuf 获得 3+0+4+0+0=7 个球。
可以验证,7 是 Lihmuf 能获得的最大总球数。使得总球数为 7 的可能的 K 值有 3 和 4。因此,K=3 是使得总球数达到最大值的最小可能的 K 值。
输入解题思路,AI测评打分。不知道怎么写?