CF1823C.Strongly Composite

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A prime number is an integer greater than 11, which has exactly two divisors. For example, 77 is a prime, since it has two divisors 1,7{1, 7}. A composite number is an integer greater than 11, which has more than two different divisors.

Note that the integer 11 is neither prime nor composite.

Let's look at some composite number vv. It has several divisors: some divisors are prime, others are composite themselves. If the number of prime divisors of vv is less or equal to the number of composite divisors, let's name vv as strongly composite.

For example, number 1212 has 66 divisors: 1,2,3,4,6,12{1, 2, 3, 4, 6, 12}, two divisors 22 and 33 are prime, while three divisors 44, 66 and 1212 are composite. So, 1212 is strongly composite. Other examples of strongly composite numbers are 44, 88, 99, 1616 and so on.

On the other side, divisors of 1515 are 1,3,5,15{1, 3, 5, 15}: 33 and 55 are prime, 1515 is composite. So, 1515 is not a strongly composite. Other examples are: 22, 33, 55, 66, 77, 1010 and so on.

You are given nn integers a1,a2,…,ana_1, a_2, \dots, a_n (ai>1a_i \gt 1). You have to build an array b1,b2,…,bkb_1, b_2, \dots, b_k such that following conditions are satisfied:

  • Product of all elements of array aa is equal to product of all elements of array bb: a1⋅a2⋅…⋅an=b1⋅b2⋅…⋅bka_1 \cdot a_2 \cdot \ldots \cdot a_n = b_1 \cdot b_2 \cdot \ldots \cdot b_k;
  • All elements of array bb are integers greater than 11 and strongly composite;
  • The size kk of array bb is the maximum possible.

Find the size kk of array bb, or report, that there is no array bb satisfying the conditions.

质数是指大于 11 的整数,且恰好有两个正因数。例如,77 是质数,因为它的正因数集合为 {1,7}\{1, 7\}。合数是指大于 11 的整数,且具有两个以上的不同正因数。

注意:整数 11 既不是质数,也不是合数。

考虑某个合数 vv。它有若干个正因数:其中一些是质数,另一些本身也是合数。若 vv 的质因数(即作为 vv 的正因数的质数)的个数小于或等于其合因数(即作为 vv 的正因数的合数)的个数,则称 vv 为强合数(strongly composite)。

例如,数 1212 有 66 个正因数:{1,2,3,4,6,12}\{1, 2, 3, 4, 6, 12\},其中 22 和 33 是质数,而 44、66 和 1212 是合数。因此,1212 是强合数。其他强合数的例子包括 44、88、99、1616 等。

另一方面,1515 的正因数为 {1,3,5,15}\{1, 3, 5, 15\}:其中 33 和 55 是质数,1515 是合数。因此,1515 不是强合数。其他非强合数的例子包括:22、33、55、66、77、1010 等。

现给定 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(满足 ai>1a_i > 1)。你需要构造一个数组 b1,b2,…,bkb_1, b_2, \dots, b_k,使其满足以下条件:

  • 数组 aa 中所有元素的乘积等于数组 bb 中所有元素的乘积:
    a1⋅a2⋅…⋅an=b1⋅b2⋅…⋅bka_1 \cdot a_2 \cdot \ldots \cdot a_n = b_1 \cdot b_2 \cdot \ldots \cdot b_k;
  • 数组 bb 的每个元素均为大于 11 的强合数;
  • 数组 bb 的长度 kk 尽可能大。

请找出满足条件的最大可能的 kk 值;若不存在满足条件的数组 bb,则报告无解。

输入格式

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

The first line of each test case contains one integer nn (1≤n≤10001 \le n \le 1000) — the size of the array aa.

The second line of each test case contains nn integer a1,a2,…ana_1, a_2, \dots a_n (2≤ai≤1072 \le a_i \le 10^7) — the array aa itself.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000)——数组 aa 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…ana_1, a_2, \dots a_n(2≤ai≤1072 \le a_i \le 10^7)——数组 aa 本身。

保证所有测试用例中 nn 的总和不超过 10001000。

输出格式

For each test case, print the size kk of array bb, or 00, if there is no array bb satisfying the conditions.

对于每个测试用例,输出数组 bb 的大小 kk;如果不存在满足条件的数组 bb,则输出 00。

输入输出样例

  • 输入#1

    8
    2
    3 6
    3
    3 4 5
    2
    2 3
    3
    3 10 14
    2
    25 30
    1
    1080
    9
    3 3 3 5 5 5 7 7 7
    20
    12 15 2 2 2 2 2 3 3 3 17 21 21 21 30 6 6 33 31 39

    输出#1

    1
    1
    0
    2
    2
    3
    4
    15

说明/提示

In the first test case, we can get array b=[18]b = [18]: a1⋅a2=18=b1a_1 \cdot a_2 = 18 = b_1; 1818 is strongly composite number.

In the second test case, we can get array b=[60]b = [60]: a1⋅a2⋅a3=60=b1a_1 \cdot a_2 \cdot a_3 = 60 = b_1; 6060 is strongly composite number.

In the third test case, there is no array bb satisfying the conditions.

In the fourth test case, we can get array b=[4,105]b = [4, 105]: a1⋅a2⋅a3=420=b1⋅b2a_1 \cdot a_2 \cdot a_3 = 420 = b_1 \cdot b_2; 44 and 105105 are strongly composite numbers.

在第一个测试用例中,我们可以得到数组 b=[18]b = [18]:a1⋅a2=18=b1a_1 \cdot a_2 = 18 = b_1;1818 是强合数。

在第二个测试用例中,我们可以得到数组 b=[60]b = [60]:a1⋅a2⋅a3=60=b1a_1 \cdot a_2 \cdot a_3 = 60 = b_1;6060 是强合数。

在第三个测试用例中,不存在满足条件的数组 bb。

在第四个测试用例中,我们可以得到数组 b=[4,105]b = [4, 105]:a1⋅a2⋅a3=420=b1⋅b2a_1 \cdot a_2 \cdot a_3 = 420 = b_1 \cdot b_2;44 和 105105 均为强合数。

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

首页