CF2180A.Carnival Wheel

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a prize wheel divided into ll sections, numbered from 00 to l−1l-1. The sections are arranged in a circle, so after section l−1l-1, the numbering continues again from section 00.

Initially, the prize pointer is at section aa. Each time you spin the wheel, the pointer moves exactly bb sections forward. That is, after one spin, the pointer moves from section aa to section (a+b) mod l(a+b)\bmod l, after two spins to (a+2b) mod l(a+2b)\bmod l, and so on∗^{\text{∗}}.

You may spin the wheel any number of times (including zero). After you stop, the section where the pointer finally lands determines your prize: you receive an amount equal to the number of that section.

What is the maximum prize you can obtain?

∗^{\text{∗}}Here, x mod yx \bmod y denotes the remainder from dividing xx by yy.

你有一个被分为 ll 个扇形区域的奖品转盘,区域编号从 00 到 l−1l-1。这些区域呈环形排列,因此在区域 l−1l-1 之后,编号再次从区域 00 开始。

初始时,指针位于区域 aa。每次旋转转盘,指针恰好向前移动 bb 个区域。即:旋转一次后,指针从区域 aa 移动到区域 (a+b) mod l(a+b)\bmod l;旋转两次后移动到 (a+2b) mod l(a+2b)\bmod l,依此类推∗^{\text{∗}}。

你可以任意次数地旋转转盘(包括零次)。当你停止旋转后,指针最终停留的区域编号即为你获得的奖品金额。

你能获得的最大奖品金额是多少?

∗^{\text{∗}}此处,x mod yx \bmod y 表示 xx 除以 yy 所得的余数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains three integers l,al, a, and bb (1≤l,b≤50001 \le l, b \le 5000, 0≤a≤l−10 \le a \le l-1).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 ll、aa 和 bb(1≤l,b≤50001 \le l, b \le 5000,0≤a≤l−10 \le a \le l-1)。

输出格式

For each test case, output the maximum prize that can be obtained.

对于每个测试用例,输出能够获得的最大奖品价值。

输入输出样例

  • 输入#1

    4
    5 3 2
    2 0 6
    8 2 4
    100 0 1

    输出#1

    4
    0
    6
    99

说明/提示

In the first test case, by spinning the wheel three times and then claiming the reward, you can obtain a maximum value of 44. The sequence of pointer positions is: 3,0,2,4,1,3,0,…3, 0, 2, 4, 1, 3, 0, \ldots

In the second test case, the pointer will remain on section 00 indefinitely.

In the fourth test case, with b=1b = 1 and starting from section 00, the pointer will iterate over all sections, including the last one.

Link to the visualizer

在第一个测试用例中,通过旋转转盘三次后领取奖励,可以获得最大值 44。指针位置序列为:3,0,2,4,1,3,0,…3, 0, 2, 4, 1, 3, 0, \ldots

在第二个测试用例中,指针将无限停留在第 00 区域。

在第四个测试用例中,当 b=1b = 1 且从第 00 区域开始时,指针将遍历所有区域(包括最后一个区域)。

可视化工具链接

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

首页