CF1332B.Composite Coloring

普及/提高-

通过率:0%

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 m11m \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)>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 ai1000a_i \le 1000 then she can always solve the task by choosing some m11m \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 .

输入格式

The first line contains a single integer tt ( 1t10001 \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 ( 1n10001 \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 ( 4ai10004 \le a_i \le 1000 ).

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

输出格式

For each test case print 22 lines. The first line should contain a single integer mm ( 1m111 \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 ( 1cim1 \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 ).

输入输出样例

  • 输入#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.

首页