310552: CF1850F. We Were Both Children

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:2 Solved:0

Description

F. We Were Both Childrentime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Mihai and Slavic were looking at a group of $n$ frogs, numbered from $1$ to $n$, all initially located at point $0$. Frog $i$ has a hop length of $a_i$.

Each second, frog $i$ hops $a_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 $n$ points (that is, in a point with a coordinate between $1$ and $n$) and the children can't place a trap in point $0$ 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?

Input

The first line of the input contains a single integer $t$ ($1 \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 $n$ ($1 \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 $n$ integers $a_1, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the lengths of the hops of the corresponding frogs.

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

Output

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

ExampleInput
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
Output
3
3
3
5
0
4
4
Note

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

  • Frog 1: $0 \to 1 \to 2 \to 3 \to \mathbf{\color{red}{4}} \to \cdots$
  • Frog 2: $0 \to 2 \to \mathbf{\color{red}{4}} \to 6 \to 8 \to \cdots$
  • Frog 3: $0 \to 3 \to 6 \to 9 \to 12 \to \cdots$
  • Frog 4: $0 \to \mathbf{\color{red}{4}} \to 8 \to 12 \to 16 \to \cdots$
  • Frog 5: $0 \to 5 \to 10 \to 15 \to 20 \to \cdots$
Therefore, if Slavic and Mihai put a trap at coordinate $4$, 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 $2$ and catch all three frogs instantly.

Input

题意翻译

## 题目描述 米哈伊和斯拉夫克正在观察一群 $ n $ 青蛙,编号从 $ 1 $ 到 $ n $,最初都位于点 $ 0 $ 。青蛙 $ i $ 的跳跃长度为 $ a_i $ 。 每秒钟,青蛙 $ i $ 向前跳跃 $ a_i $ 个单位。在青蛙开始跳跃之前,斯拉维克和米哈伊可以在一个坐标上放置一个陷阱,以便捕捉所有经过相应坐标的青蛙。 但是,孩子们不能离开家太远,所以他们只能在前 $ n $ 个点(即坐标在 $ 1 $ 和 $ n $ 之间的点)放置一个陷阱,而且孩子们不能在点 $ 0 $ 放置陷阱,因为他们害怕青蛙。 你能帮助斯拉维奇和米哈伊找出用陷阱最多能捕捉多少只青蛙吗? ## 输入格式 输入格式的第一行包含一个整数 $ t $ ( $ 1 \le t \le 100 $ ) - 测试用例的数量。下面是测试用例的描述。 每个测试用例的第一行包含一个整数 $ n $ ( $ 1 \leq n \leq 2 \cdot 10^5 $ ) --青蛙的数量,相当于斯拉夫和米哈伊放置陷阱的距离。 每个测试用例的第二行包含 n 个整数 $ a_1, \ldots, a_n $ ( $ 1 \leq a_i \leq 10^9 $ ) - 对应青蛙跳跃的长度。 保证所有测试案例中 $ n $ 的总和不超过 $ 2 \cdot 10^5 $ . ## 输出格式 对每个测试用例输出一个整数 - 斯拉维克和米哈伊使用陷阱捕捉青蛙的最大数量。 ## 提示 在第一个测试案例中,青蛙的跳动情况如下: - 青蛙 1: $ 0 \to 1 \to 2 \to 3 \to \mathbf{\color{red}{4}} \to \cdots $ - 青蛙 2: $ 0 \to 2 \to \mathbf{\color{red}{4}} \to 6 \to 8 \to \cdots $ - 青蛙 3: $ 0\to 3\to 6\to 9\to 12\to \cdots $ - 青蛙 4: $ 0\to 8\to 12\to 8\to 12\to 16\to \cdots $ - 青蛙 5: $ 0 \to 5 \to 10 \to 15 \to 20 \to \cdots $ 因此,如果斯拉维奇和米哈伊在坐标 $ 4 $ 处放一个捕捉器,他们可以捕捉到三只青蛙:青蛙 1、2 和 4。在第二个测试案例中,斯拉维克和米哈伊可以在坐标 $ 2 $ 处放置陷阱并立即捕获所有三只青蛙。

Output

题目大意:
米哈伊和斯拉夫在观察一群从1到n编号的青蛙,所有青蛙最初都位于点0。青蛙i每次跳跃ai单位长度。每一秒钟,青蛙i会向前跳跃ai单位。在青蛙开始跳跃之前,米哈伊和斯拉夫可以在一个坐标上放置一个陷阱,以捕捉所有将会通过该坐标的青蛙。然而,孩子们不能远离他们的家,因此他们只能在前n个点(即坐标在1到n之间的点)放置陷阱,而且由于他们害怕青蛙,不能在点0放置陷阱。你能帮助米哈伊和斯拉夫找出他们能捕捉到的青蛙的最大数量吗?

输入数据格式:
输入的第一行包含一个整数t(1≤t≤100)——测试用例的数量。接下来是每个测试用例的描述。
每个测试用例的第一行包含一个整数n(1≤n≤2×10^5)——青蛙的数量,这也等于斯拉夫和米哈伊可以放置陷阱的距离。
每个测试用例的第二行包含n个整数a1,…,an(1≤ai≤10^9)——相应青蛙的跳跃长度。
保证所有测试用例的n之和不超过2×10^5。

输出数据格式:
对于每个测试用例,输出一个整数——斯拉夫和米哈伊能捕捉到的青蛙的最大数量。

示例:
输入:
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
输出:
3
3
3
5
0
4
4

注意:
在第一个测试用例中,如果斯拉夫和米哈伊在坐标4放置一个陷阱,他们可以捕捉到三只青蛙:青蛙1、2和4。可以证明他们不能捕捉到更多的青蛙。
在第二个测试用例中,斯拉夫和米哈伊可以在坐标2放置一个陷阱并立即捕捉到所有三只青蛙。题目大意: 米哈伊和斯拉夫在观察一群从1到n编号的青蛙,所有青蛙最初都位于点0。青蛙i每次跳跃ai单位长度。每一秒钟,青蛙i会向前跳跃ai单位。在青蛙开始跳跃之前,米哈伊和斯拉夫可以在一个坐标上放置一个陷阱,以捕捉所有将会通过该坐标的青蛙。然而,孩子们不能远离他们的家,因此他们只能在前n个点(即坐标在1到n之间的点)放置陷阱,而且由于他们害怕青蛙,不能在点0放置陷阱。你能帮助米哈伊和斯拉夫找出他们能捕捉到的青蛙的最大数量吗? 输入数据格式: 输入的第一行包含一个整数t(1≤t≤100)——测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含一个整数n(1≤n≤2×10^5)——青蛙的数量,这也等于斯拉夫和米哈伊可以放置陷阱的距离。 每个测试用例的第二行包含n个整数a1,…,an(1≤ai≤10^9)——相应青蛙的跳跃长度。 保证所有测试用例的n之和不超过2×10^5。 输出数据格式: 对于每个测试用例,输出一个整数——斯拉夫和米哈伊能捕捉到的青蛙的最大数量。 示例: 输入: 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 输出: 3 3 3 5 0 4 4 注意: 在第一个测试用例中,如果斯拉夫和米哈伊在坐标4放置一个陷阱,他们可以捕捉到三只青蛙:青蛙1、2和4。可以证明他们不能捕捉到更多的青蛙。 在第二个测试用例中,斯拉夫和米哈伊可以在坐标2放置一个陷阱并立即捕捉到所有三只青蛙。

加入题单

上一题 下一题 算法标签: