CF1475G.Strange Beauty

普及+/提高

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp found on the street an array aa of nn elements.

Polycarp invented his criterion for the beauty of an array. He calls an array aa beautiful if at least one of the following conditions must be met for each different pair of indices i≠ji \ne j:

  • aia_i is divisible by aja_j;
  • or aja_j is divisible by aia_i.

For example, if:

  • n=5n=5 and a=[7,9,3,14,63]a=[7, 9, 3, 14, 63], then the aa array is not beautiful (for i=4i=4 and j=2j=2, none of the conditions above is met);
  • n=3n=3 and a=[2,14,42]a=[2, 14, 42], then the aa array is beautiful;
  • n=4n=4 and a=[45,9,3,18]a=[45, 9, 3, 18], then the aa array is not beautiful (for i=1i=1 and j=4j=4 none of the conditions above is met);

Ugly arrays upset Polycarp, so he wants to remove some elements from the array aa so that it becomes beautiful. Help Polycarp determine the smallest number of elements to remove to make the array aa beautiful.

Polycarp 在街上发现了一个包含 nn 个元素的数组 aa。

Polycarp 提出了他自己定义的数组“优美性”判据。他称一个数组 aa 是优美的,当且仅当对任意一对互异的下标 i≠ji \ne j,以下两个条件中至少有一个成立:

  • aia_i 能被 aja_j 整除;
  • 或 aja_j 能被 aia_i 整除。

例如:

  • 若 n=5n=5 且 a=[7,9,3,14,63]a=[7, 9, 3, 14, 63],则数组 aa 不优美(当 i=4i=4、j=2j=2 时,上述两个条件均不满足);
  • 若 n=3n=3 且 a=[2,14,42]a=[2, 14, 42],则数组 aa 优美;
  • 若 n=4n=4 且 a=[45,9,3,18]a=[45, 9, 3, 18],则数组 aa 不优美(当 i=1i=1、j=4j=4 时,上述两个条件均不满足);

丑陋的数组令 Polycarp 感到不快,因此他希望从数组 aa 中删除若干元素,使其变为优美的。请帮助 Polycarp 确定:为使数组 aa 变为优美,所需删除的最少元素个数是多少?

输入格式

The first line contains one integer tt (1≤t≤101 \leq t \leq 10) — the number of test cases. Then tt test cases follow.

The first line of each test case contains one integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn numbers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5) — elements of the array aa.

第一行包含一个整数 tt(1≤t≤101 \leq t \leq 10)—— 测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5)—— 数组 aa 的元素。

输出格式

For each test case output one integer — the minimum number of elements that must be removed to make the array aa beautiful.

对于每个测试用例,输出一个整数——使数组 aa 变为“美丽”的所需删除的最少元素个数。

输入输出样例

  • 输入#1

    4
    5
    7 9 3 14 63
    3
    2 14 42
    4
    45 9 3 18
    3
    2 2 8

    输出#1

    2
    0
    1
    0

说明/提示

In the first test case, removing 77 and 1414 will make array aa beautiful.

In the second test case, the array aa is already beautiful.

In the third test case, removing one of the elements 4545 or 1818 will make the array aa beautiful.

In the fourth test case, the array aa is beautiful.

在第一个测试用例中,移除 77 和 1414 后,数组 aa 将变得优美。

在第二个测试用例中,数组 aa 本身已经是优美的。

在第三个测试用例中,移除元素 4545 或 1818 中的任意一个,即可使数组 aa 变得优美。

在第四个测试用例中,数组 aa 是优美的。

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

首页