CF1332B.Composite Coloring

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 11. For example, the following numbers are composite: 66, 44, 120120, 2727. The following numbers aren't: 11, 22, 33, 1717, 9797.

Alice is given a sequence of nn composite numbers a1,a2,…,ana_1,a_2,\ldots,a_n.

She wants to choose an integer m≤11m \le 11 and color each element one of mm colors from 11 to mm so that:

  • for each color from 11 to mm there is at least one element of this color;
  • each element is colored and colored exactly one color;
  • the greatest common divisor of any two elements that are colored the same color is greater than 11, i.e. gcd⁡(ai,aj)>1\gcd(a_i, a_j) \gt 1 for each pair i,ji, j if these elements are colored the same color.

Note that equal elements can be colored different colors — you just have to choose one of mm colors for each of the indices from 11 to nn.

Alice showed already that if all ai≤1000a_i \le 1000 then she can always solve the task by choosing some m≤11m \le 11.

Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some mm from 11 to 1111.

如果一个正整数可以表示为两个均大于 11 的正整数的乘积,则称其为合数。例如,以下数字是合数:66、44、120120、2727;而以下数字不是合数:11、22、33、1717、9797。

Alice 被给定一个由 nn 个合数组成的序列 a1,a2,…,ana_1, a_2, \ldots, a_n。

她希望选择一个整数 m≤11m \le 11,并将序列中每个元素染上 mm 种颜色之一(颜色编号为 11 至 mm),使得满足以下条件:

  • 对于每种颜色 11 至 mm,至少有一个元素被染成该颜色;
  • 每个元素都被染色,且恰好染一种颜色;
  • 任意两个被染成相同颜色的元素的最大公约数大于 11,即:对任意下标对 i,ji, j,若 aia_i 与 aja_j 被染成同一种颜色,则必有 gcd⁡(ai,aj)>1\gcd(a_i, a_j) > 1。

注意:相等的元素可以染成不同颜色——你只需为下标 11 至 nn 中的每个位置选定 mm 种颜色之一即可。

Alice 已经证明:只要所有 ai≤1000a_i \le 1000,那么总存在某个 m≤11m \le 11,使得该染色任务总有解。

请帮助 Alice 找到一种满足要求的染色方案。注意:你无需最小化或最大化所用颜色数,只需找到一种使用 11 至 1111 中某个 mm 的可行解即可。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Then the descriptions of the test cases follow.

The first line of the test case contains a single integer nn (1≤n≤10001 \le n \le 1000) — the amount of numbers in a sequence aa.

The second line of the test case contains nn composite integers a1,a2,…,ana_1,a_2,\ldots,a_n (4≤ai≤10004 \le a_i \le 1000).

It is guaranteed that the sum of nn over all test cases doesn't exceed 10410^4.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000)—— 表示序列 aa 中数字的个数。

每个测试用例的第二行包含 nn 个合数 a1,a2,…,ana_1,a_2,\ldots,a_n(4≤ai≤10004 \le a_i \le 1000)。

保证所有测试用例的 nn 之和不超过 10410^4。

输出格式

For each test case print 22 lines. The first line should contain a single integer mm (1≤m≤111 \le m \le 11) — the number of used colors. Consider colors to be numbered from 11 to mm. The second line should contain any coloring that satisfies the above conditions. Print nn integers c1,c2,…,cnc_1, c_2, \dots, c_n (1≤ci≤m1 \le c_i \le m), where cic_i is the color of the ii-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some mm from 11 to 1111.

Remember that each color from 11 to mm should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 11).

对每个测试用例,输出 22 行。第一行应包含一个整数 mm(1≤m≤111 \le m \le 11),表示所使用的颜色数量。将颜色编号为 11 到 mm。第二行应输出任意一种满足上述条件的染色方案。输出 nn 个整数 c1,c2,…,cnc_1, c_2, \dots, c_n(1≤ci≤m1 \le c_i \le m),其中 cic_i 表示第 ii 个元素的颜色。若存在多种解,可输出任意一种。注意:你无需最小化或最大化颜色数量,只需找到某个满足 1≤m≤111 \le m \le 11 的解即可。

注意:颜色 11 至 mm 中的每一种都至少需使用一次;任意两个同色元素不应互质(即它们的最大公约数应大于 11)。

输入输出样例

  • 输入#1

    3
    3
    6 10 15
    2
    4 9
    23
    437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961

    输出#1

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

说明/提示

In the first test case, gcd⁡(6,10)=2\gcd(6,10)=2, gcd⁡(6,15)=3\gcd(6,15)=3 and gcd⁡(10,15)=5\gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case.

In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.

在第一个测试用例中,gcd⁡(6,10)=2\gcd(6,10)=2,gcd⁡(6,15)=3\gcd(6,15)=3,且 gcd⁡(10,15)=5\gcd(10,15)=5。因此,将所有元素染成同一种颜色是合法的。注意,在该测试用例中,还存在其他满足 Alice 要求的染色方案。

在第二个测试用例中,每种颜色仅有一个元素,因此该染色方案一定满足 Alice 的要求。

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

首页