CF1850F.We Were Both Children

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mihai and Slavic were looking at a group of nn frogs, numbered from 11 to nn, all initially located at point 00. Frog ii has a hop length of aia_i.

Each second, frog ii hops aia_i units forward. Before any frogs start hopping, Slavic and Mihai can place exactly one trap in a coordinate in order to catch all frogs that will ever pass through the corresponding coordinate.

However, the children can't go far away from their home so they can only place a trap in the first nn points (that is, in a point with a coordinate between 11 and nn) and the children can't place a trap in point 00 since they are scared of frogs.

Can you help Slavic and Mihai find out what is the maximum number of frogs they can catch using a trap?

米海和斯拉维克正在观察一群 nn 只青蛙,编号从 11 到 nn,所有青蛙初始时均位于坐标点 00。青蛙 ii 的单次跳跃长度为 aia_i。

每一秒,青蛙 ii 向前跳跃 aia_i 个单位长度。在任何青蛙开始跳跃之前,斯拉维克和米海可以在某个坐标位置恰好放置一个陷阱,以捕获所有曾经经过该坐标的青蛙。

然而,孩子们不能离家太远,因此他们只能将陷阱放置在前 nn 个坐标点上(即坐标值在 11 到 nn 之间的整数点),且他们不能将陷阱放在坐标点 00 处(因为他们害怕青蛙)。

你能帮斯拉维克和米海找出:使用一个陷阱最多能捕获多少只青蛙?

输入格式

The first line of the input contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the number of frogs, which equals the distance Slavic and Mihai can travel to place a trap.

The second line of each test case contains nn integers a1,…,ana_1, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the lengths of the hops of the corresponding frogs.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 表示青蛙的数量,该数值也等于 Slavic 和 Mihai 可以移动以放置陷阱的距离。

每个测试用例的第二行包含 nn 个整数 a1,…,ana_1, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 表示对应青蛙的跳跃长度。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case output a single integer — the maximum number of frogs Slavic and Mihai can catch using a trap.

对于每个测试用例,输出一个整数——Slavic 和 Mihai 使用陷阱最多能捕获的青蛙数量。

输入输出样例

  • 输入#1

    7
    5
    1 2 3 4 5
    3
    2 2 2
    6
    3 1 3 4 9 10
    9
    1 3 2 4 2 3 7 8 5
    1
    10
    8
    7 11 6 8 12 4 4 8
    10
    9 11 9 12 1 7 2 5 8 10

    输出#1

    3
    3
    3
    5
    0
    4
    4

说明/提示

In the first test case, the frogs will hop as follows:

  • Frog 1: 0→1→2→3→4→⋯0 \to 1 \to 2 \to 3 \to \mathbf{\color{red}{4}} \to \cdots
  • Frog 2: 0→2→4→6→8→⋯0 \to 2 \to \mathbf{\color{red}{4}} \to 6 \to 8 \to \cdots
  • Frog 3: 0→3→6→9→12→⋯0 \to 3 \to 6 \to 9 \to 12 \to \cdots
  • Frog 4: 0→4→8→12→16→⋯0 \to \mathbf{\color{red}{4}} \to 8 \to 12 \to 16 \to \cdots
  • Frog 5: 0→5→10→15→20→⋯0 \to 5 \to 10 \to 15 \to 20 \to \cdots

Therefore, if Slavic and Mihai put a trap at coordinate 44, they can catch three frogs: frogs 1, 2, and 4. It can be proven that they can't catch any more frogs.

In the second test case, Slavic and Mihai can put a trap at coordinate 22 and catch all three frogs instantly.

在第一个测试用例中,青蛙的跳跃路径如下:

  • 青蛙 1:0→1→2→3→4→⋯0 \to 1 \to 2 \to 3 \to \mathbf{\color{red}{4}} \to \cdots
  • 青蛙 2:0→2→4→6→8→⋯0 \to 2 \to \mathbf{\color{red}{4}} \to 6 \to 8 \to \cdots
  • 青蛙 3:0→3→6→9→12→⋯0 \to 3 \to 6 \to 9 \to 12 \to \cdots
  • 青蛙 4:0→4→8→12→16→⋯0 \to \mathbf{\color{red}{4}} \to 8 \to 12 \to 16 \to \cdots
  • 青蛙 5:0→5→10→15→20→⋯0 \to 5 \to 10 \to 15 \to 20 \to \cdots

因此,若斯拉维克和米海将陷阱设置在坐标 44 处,他们可以捕获三只青蛙:青蛙 1、青蛙 2 和青蛙 4。可以证明,他们无法捕获更多青蛙。

在第二个测试用例中,斯拉维克和米海可将陷阱设置在坐标 22 处,从而立即捕获全部三只青蛙。

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

首页