description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) β the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer β the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | INF = 1000000000000000000
def sol1(A):
max3 = 0
for x in A:
if x % 3 == 0:
x -= 3
max3 = max(max3, x // 3)
else:
max3 = max(max3, x // 3)
return 2 + max3
def sol2(A):
max3 = 0
for x in A:
if x % 3 == 1:
return INF
max3 = max(max3, x // 3)
return 1 + max3
def sol3(A):
max3 = 0
for x in A:
if x % 3 == 2:
return INF
max3 = max(max3, x // 3)
return 1 + max3
def sol4(A):
max3 = 0
for x in A:
if x == 1:
return INF
if x % 3 == 1:
x -= 4
max3 = max(max3, x // 3)
elif x % 3 == 2:
max3 = max(max3, x // 3)
else:
max3 = max(max3, x // 3)
return 2 + max3
def sol5(A):
max3 = 0
for x in A:
if x % 3 == 1:
return INF
if x % 3 == 2:
return INF
max3 = max(max3, x // 3)
return max3
def solve():
N = int(input())
A = [int(x) for x in input().split()]
mini = sol1(A)
mini = min(mini, sol2(A))
mini = min(mini, sol3(A))
mini = min(mini, sol4(A))
mini = min(mini, sol5(A))
print(mini)
T = int(input())
for i in range(T):
solve() | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) β the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer β the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | T = int(input())
for i in range(T):
n = int(input())
l = list(map(int, input().split()))
l.sort()
isMod1 = False
isMod2 = False
one = l[0] == 1
smaller = False
for j in range(n):
if l[j] % 3 == 1:
isMod1 = True
elif l[j] % 3 == 2:
isMod2 = True
if l[j] == l[-1] - 1:
smaller = True
maxMod3 = l[-1] % 3
if maxMod3 == 2 and isMod1 == True and isMod2 == True:
print(l[-1] // 3 + 2)
elif isMod1 == False and isMod2 == False:
print(l[-1] // 3)
elif isMod1 != isMod2:
print(l[-1] // 3 + 1)
elif maxMod3 == 0 and isMod1 == True and isMod2 == True:
print(l[-1] // 3 + 1)
elif maxMod3 == 1 and isMod1 == True and isMod2 == True:
if not one and not smaller:
print(l[-1] // 3 + 1)
else:
print(l[-1] // 3 + 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) β the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer β the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
r = (max(a) + 2) // 3
ans = r + 1
for take_ones in range(3):
for take_twos in range(3):
loop_ans = 0
for i in range(n):
cur_ans = 10**9
if a[i] % 3 == 1 and not take_ones and (take_twos < 2 or a[i] < 4):
break
elif a[i] % 3 == 2 and not take_twos and take_ones < 2:
break
if a[i] % 3 == 0:
cur_ans = a[i] // 3
if a[i] % 3 == 1:
if take_ones:
cur_ans = min(cur_ans, (a[i] - 1) // 3)
if take_twos >= 2 and a[i] >= 4:
cur_ans = min(cur_ans, (a[i] - 4) // 3)
if a[i] % 3 == 2:
cur_ans = min(cur_ans, (a[i] - 2) // 3)
loop_ans = max(loop_ans, cur_ans)
else:
loop_ans += take_ones + take_twos
ans = min(ans, loop_ans)
if ans == r:
break
if ans == r:
break
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) β the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer β the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
answer = max(a)
for i in range(2):
s = set(j for j in range(i + 1))
for j in range(3):
if j > 0:
t = set()
for item in s:
t.add(item + 2)
s |= t
answer = min(
answer,
max(
min(
(
(item - v) // 3 + i + j
if item >= v and (item - v) % 3 == 0
else answer
)
for v in s
)
for item in a
),
)
print(answer) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | import sys
input = lambda: sys.stdin.readline().rstrip()
def I():
return [int(iI) for iI in input().split()]
def II():
return int(input())
def SI():
return [i for i in input()]
for _ in range(II()):
n = II()
a = I()
k = 1
ans = [0] * len(a)
for i in range(2, 32):
flag = 0
for j in range(len(a)):
if a[j] % i == 0:
ans[j] = k
flag = 1
a[j] = 1
if flag == 1:
k += 1
print(len(set(ans)))
print(*ans) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for i in range(int(input())):
n = int(input())
primes = {
(2): 0,
(3): 0,
(5): 0,
(7): 0,
(11): 0,
(13): 0,
(17): 0,
(19): 0,
(23): 0,
(29): 0,
(31): 0,
}
l = list(map(int, input().split()))
for j in primes:
l1 = []
for k in range(n):
if l[k] % j == 0:
l1.append((l[k], k))
primes[j] = l1
d = {}
for k in range(n):
d[k] = 0
index = 1
for j in primes:
check = 0
for k in range(len(primes[j])):
if d[primes[j][k][1]] == 0:
check = 1
d[primes[j][k][1]] = index
if check == 1:
index += 1
max = 0
for j in d:
if max < d[j]:
max = d[j]
print(max)
for j in d:
print(d[j], end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
127,
131,
137,
139,
149,
151,
157,
163,
167,
173,
179,
181,
191,
193,
197,
199,
211,
223,
227,
229,
233,
239,
241,
251,
257,
263,
269,
271,
277,
281,
283,
293,
307,
311,
313,
317,
331,
337,
347,
349,
353,
359,
367,
373,
379,
383,
389,
397,
401,
409,
419,
421,
431,
433,
439,
443,
449,
457,
461,
463,
467,
479,
487,
491,
499,
]
t = int(input())
for i in range(t):
length = int(input())
arr = [int(x) for x in input().split()]
colored = [(0) for x in range(length)]
clr = 1
ans = ""
ps = colored.copy()
for indp in range(len(primes)):
flg = 0
for indx in range(length):
if colored[indx]:
continue
if arr[indx] % primes[indp] == 0:
colored[indx] = clr
ps[indx] = primes[indp]
flg = 1
if flg:
clr += 1
for ix in colored:
ans += str(ix) + " "
print(len(set(colored)))
print(ans) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | I = lambda: int(input())
M = lambda: map(int, input().split())
L = lambda: list(M())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(I()):
n = I()
a = L()
li = []
use = [False] * 11
for i in range(n):
for j in range(11):
if a[i] % p[j] == 0:
li.append(j)
use[j] = True
break
cnt = 0
num = []
for i in range(11):
num.append(cnt)
if use[i]:
cnt += 1
print(cnt)
for i in range(n):
print(num[li[i]] + 1, end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | d = {i: (0) for i in range(1001)}
pos = 1
v = int(1001**0.5) + 1
for i in range(2, v):
if d[i] == 0:
d[i] = i
for j in range(i * i, 1001, i):
if j % i == 0:
d[j] = i
cases = int(input())
for t in range(cases):
n = int(input())
a = list(map(int, input().split()))
pos = 0
d1 = {}
v = []
for i in a:
if d[i] not in d1:
pos += 1
d1[d[i]] = pos
v.append(d1[d[i]])
print(pos)
print(*v) | ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def getPrime(x):
for i in range(2, x):
if x % i == 0:
return i
return -1
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for T in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
used = [(False) for x in range(11)]
for i in range(n):
x = primes.index(getPrime(a[i]))
used[x] = True
cnt = 0
num = []
for i in range(11):
num.append(cnt)
if used[i]:
cnt += 1
print(cnt)
for i in range(n):
x = primes.index(getPrime(a[i]))
print(num[x] + 1, end=" ")
print() | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
T = int(input())
for _ in range(T):
N = int(input())
A = [int(a) for a in input().split()]
X = [-1] * N
D = [-1] * 11
for i, a in enumerate(A):
for j, p in enumerate(P):
if a % p == 0:
X[i] = j
if D[j] < 0:
D[j] = max(D) + 1
break
print(max(D) + 1)
print(*[(D[x] + 1) for x in X]) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def getPrimes(n):
count = 0
primes = [True] * (n + 1)
primes[0] = primes[1] = False
for i in range(2, n + 1):
if primes[i]:
count += 1
j = 2
while i * j <= n:
primes[i * j] = False
j += 1
return primes
def solve(arr, primes, ans):
colors = [0] * len(arr)
m = 1
for i in range(2, len(primes)):
if primes[i]:
indices = []
for j in range(len(arr)):
if arr[j] % i == 0 and colors[j] == 0:
indices.append(j)
if indices:
for j in indices:
colors[j] = m
m += 1
ans.append([m - 1])
ans.append(colors)
def main():
primes = getPrimes(10**3)
t = int(input())
ans = []
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
solve(arr, primes, ans)
for i in ans:
for j in i:
print(j, end=" ")
print()
main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for _ in range(0, t):
n = int(input())
l = list(map(int, input().split()))
s = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
z = []
f = []
maxi = 1
for i in l:
for k, j in enumerate(s):
if i % j == 0:
if not j in f:
f.append(j)
z.append(f.index(j) + 1)
break
print(len(f))
for i in z:
print(i, end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in " " * int(input()):
a = int(input())
z = []
k = {}
for i in map(int, input().split()):
for j in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
if i % j == 0:
if j not in k:
k[j] = len(k) + 1
z += [k[j]]
break
print(len(k))
print(*z)
k = {} | FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
t = int(input())
for i in range(0, t):
n = int(input())
a = list(map(int, input().split()))
ans = []
d = []
len_d = 0
for k in range(0, n):
flag = 0
if k == 0:
for p in range(0, 11):
if a[k] % primes[p] == 0:
d.append(primes[p])
len_d = len_d + 1
ans.append(len_d)
break
else:
for j in range(0, len_d):
if a[k] % d[j] == 0:
ans.append(j + 1)
flag = 1
break
if flag == 0:
for p in range(0, 11):
if a[k] % primes[p] == 0:
d.append(primes[p])
len_d = len_d + 1
ans.append(len_d)
break
ll = len(ans)
print(len_d)
for k in range(0, ll):
if k == ll - 1:
print(ans[k])
else:
print(ans[k], end=" ") | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
ans = [11] * n
cnt = 1
for i in range(11):
flag = False
for j in range(n):
if a[j] % prime[i] == 0:
flag = True
ans[j] = min(cnt, ans[j])
if flag:
cnt += 1
for i in range(max(ans) - 1, 0, -1):
if i not in ans:
for j in range(n):
if ans[j] > i:
ans[j] -= 1
print(max(ans))
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | from sys import stdin
def solve(n, a):
k = 0
c = [0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
h = [0] * n
d = {}
for i in range(1, 12):
for j in range(n):
if a[j] == -1:
continue
if a[j] % c[i] == 0:
if c[i] not in d:
d[c[i]] = 1
k += 1
h[j] = k
a[j] = -1
print(k)
for i in h:
print(i, end=" ")
print()
def main():
input = stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
solve(n, a)
main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
R = lambda: map(int, input().rstrip().split())
for _ in range(int(input())):
n = int(input())
a = list(R())
ans = []
colours = {}
l = 0
for x in a:
for i in range(11):
if x % primes[i] == 0:
color = colours.get(i, 0)
if color == 0:
l += 1
colours[i] = l
color = l
ans += [color]
break
print(l)
print(*ans) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | cs = [(-1) for i in range(1001)]
cnt = 0
for i in range(2, 1001):
if cs[i] == -1:
cnt += 1
for j in range(2 * i, 1001, i):
if cs[j] == -1:
cs[j] = cnt
t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int, input().split()))
used = list(set([cs[v] for v in A]))
idc = {}
for i in range(len(used)):
idc[used[i]] = i + 1
A = list(map(lambda v: idc[cs[v]], A))
print(len(used))
print(" ".join(map(str, A))) | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def ndc(k):
t = int(k**0.5)
for i in range(2, t + 1):
if k % i == 0:
return i
return k
kl = int(input())
for l in range(kl):
rz = []
s = set()
A = {}
nr = 0
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
prd = ndc(a[i])
if prd not in s:
s.add(prd)
nr += 1
A[prd] = nr
rz += [A[prd]]
print(nr)
print(*rz) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
while t:
t -= 1
n = int(input())
a = [int(x) for x in input().split()]
d = {}
c = 0
ans = []
for i in range(n):
flag = 0
temp = -1
for j in p:
if a[i] % j == 0:
if j in d.keys():
ans += [d[j]]
flag = 1
break
else:
temp = j
break
if flag == 0:
c += 1
d[temp] = c
ans += [c]
print(c)
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | import sys
input = lambda: sys.stdin.readline().rstrip()
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
an = 0
ans = []
tw = 0
tr = 0
sem = 0
p = 0
od = 0
trin = 0
dev = 0
dvtr = 0
dvd = 0
tro = 0
trse = 0
semnad = 0
for i in a:
if i % 2 == 0:
if tw == 0:
tw = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(tw)
elif i % 3 == 0:
if tr == 0:
tr = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(tr)
elif i % 5 == 0:
if p == 0:
p = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
ans.append(p)
elif i % 7 == 0:
if sem == 0:
sem = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(sem)
elif i % 11 == 0:
if od == 0:
od = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(od)
elif i % 13 == 0:
if trin == 0:
trin = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(trin)
elif i % 19 == 0:
if dev == 0:
dev = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(dev)
elif i % 23 == 0:
if dvtr == 0:
dvtr = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(dvtr)
elif i % 29 == 0:
if dvd == 0:
dvd = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(dvd)
elif i % 31 == 0:
if tro == 0:
tro = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(tro)
elif i % 17 == 0:
if semnad == 0:
semnad = (
max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
)
ans.append(semnad)
print(max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse))
print(*ans) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
l = []
lst = []
for i in range(int(input())):
input()
for i1, j in enumerate(map(int, input().split())):
for n in p:
if j % n == 0:
if n in l:
lst.append(l.index(n) + 1)
break
else:
l.append(n)
lst.append(l.index(n) + 1)
break
s = set(lst)
print(len(s))
print(*lst)
lst.clear()
l.clear() | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | import sys
input = sys.stdin.readline
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
Q = int(input())
Query = []
for _ in range(Q):
N = int(input())
A = list(map(int, input().split()))
Query.append((N, A))
for N, A in Query:
ans = []
Nums = {}
for a in A:
for i, p in enumerate(primes):
if a % p == 0:
if not p in Nums:
Nums[p] = len(Nums) + 1
ans.append(Nums[p])
break
print(len(Nums))
print(*ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | from sys import stdin
def find_smallest_factor(n):
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for p in primes:
if n % p == 0:
return p
def choose_colours(num_list):
factor_list = list(map(find_smallest_factor, num_list))
unique_factors = list(set(factor_list))
prime2colour = {k: (v + 1) for v, k in enumerate(unique_factors)}
colours = [prime2colour[d] for d in factor_list]
return colours
N = int(stdin.readline())
for _ in range(N):
_ = int(stdin.readline())
num_list = list(map(int, stdin.readline().split()))
colours = choose_colours(num_list)
print(len(set(colours)))
print(*colours, sep=" ") | FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def solve(array):
current = 1
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
ans = [(-1) for i in range(len(array))]
for prime in primes:
used = False
for i in range(len(array)):
if ans[i] == -1:
if array[i] % prime == 0:
ans[i] = current
used = True
if used:
current += 1
print(current - 1)
print(*ans)
x = int(input())
while x > 0:
_ = input()
array = list(map(int, input().split()))
solve(array)
x -= 1 | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for i in range(t):
n = int(input())
lis = list(map(int, input().split()))
clr_map = [(0) for i in range(n)]
maxi = max(lis)
j = 2
clr = 1
while j * j <= maxi:
look = False
for k in range(n):
if lis[k] % j == 0:
if clr_map[k] == 0:
clr_map[k] = clr
look = True
j += 1
if look:
clr += 1
if clr > 12:
print("-1")
else:
print(clr - 1)
for j in clr_map:
print(j, end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = []
for i in range(2, 1001):
flag = True
for j in range(2, int(i**0.5) + 1):
if i % j == 0:
flag = False
if flag:
primes.append(i)
t = int(input())
while t:
n = int(input())
a = list(map(int, input().split()))
color = [(0) for i in range(n)]
m = 1
for i in range(len(primes)):
flag = False
for j in range(n):
if a[j] % primes[i] == 0 and color[j] == 0:
color[j] = m
flag = True
if flag:
m += 1
print(m - 1)
print(*color)
t -= 1 | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for tt in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
is_coloured = list([0] * n)
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for pp in primes:
col = max(is_coloured) + 1
for i in range(n):
if is_coloured[i] == 0 and a[i] % pp == 0:
is_coloured[i] = col
print(max(is_coloured))
s = ""
for x in is_coloured:
s += str(x)
s += " "
print(s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | import sys
input = sys.stdin.readline
T = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(T):
N = int(input())
A = list(map(int, input().split()))
used = [False] * 11
Ans = []
for a in A:
for idx_primes, p in enumerate(primes):
if a % p == 0:
Ans.append(idx_primes)
used[idx_primes] = True
break
else:
assert False
M = [-1] * 11
cnt = 0
for i, m in enumerate(used):
if m:
cnt += 1
M[i] = cnt
print(cnt)
print(" ".join([str(M[a]) for a in Ans])) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for i in range(t):
n = int(input())
l1 = list(map(int, input().split()))
colors = list()
r = [0] * len(l1)
for i in range(2, 1000):
a = 1
for color in colors:
if i % color == 0:
a = 0
break
if a:
colors.append(i)
b = False
for j in range(len(l1)):
if l1[j] % i == 0 and not r[j]:
b = True
r[j] = len(colors)
if not b:
colors.pop()
if sum(map(bool, r)) == len(l1):
break
print(len(colors))
print(" ".join(map(str, r))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for i in range(t):
n = int(input())
l = list(map(int, input().split()))
d = [(0) for _ in range(n)]
r = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
m = 1
for s in r:
a = False
for i in range(n):
if l[i] % s == 0 and d[i] == 0:
d[i] = m
a = True
if a:
m = m + 1
print(max(d))
print(*d) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def get(x):
for i in range(2, x):
if x % i == 0:
return i
return -1
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
n = int(input())
a = list(map(lambda x: pr.index(get(int(x))), input().split()))
used = [0] * 11
for i in a:
used[i] = 1
cnt = 0
num = []
for i in range(11):
num.append(cnt)
if used[i]:
cnt += 1
print(cnt)
print(*[(num[i] + 1) for i in a]) | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
m = 0
d = {}
for i in range(n):
for j in range(11):
if a[i] % pr[j] == 0:
if j in d:
a[i] = d[j]
else:
m += 1
a[i] = m
d[j] = m
break
print(m)
print(*a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for case_num in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
used = set()
color = []
for i in a:
for prime in primes:
if i % prime == 0:
color.append(prime)
used.add(prime)
break
lookup = dict()
idx = 1
for c in used:
lookup[c] = idx
idx += 1
print(len(used))
print(" ".join(map(str, [lookup[i] for i in color]))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
n = int(input())
a = [int(o) for o in input().split()]
kk = 1
ans = [0] * n
i = 2
while i <= 1000:
flag = 0
for j in range(n):
if ans[j] == 0 and a[j] % i == 0:
ans[j] = kk
flag = 1
if flag == 1:
kk += 1
i += 1
kk -= 1
print(kk)
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split(" ")))
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
res = [(-1) for _ in range(n)]
current_color = 1
if len(arr) <= 11:
print(n)
for i in range(1, n + 1):
print(i, end=" ")
print()
else:
for p in prime:
ok = False
for j in range(n):
if res[j] != -1:
continue
if arr[j] % p:
continue
ok = True
res[j] = current_color
if ok:
current_color += 1
print(current_color - 1)
for s in range(n):
print(res[s], end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def factor(i):
pr = []
e = 2
while e**2 <= i:
if i % e == 0:
pr.append(e)
while i % e == 0:
i = i // e
e += 1
if i > 1:
pr.append(i)
return pr
def solve():
n = int(input())
nums = list(map(int, input().split()))
numf = list(map(factor, nums))
colors = [0] * n
primes = [i for i in range(2, 1001) if factor(i) == [i]]
c = 0
for p in primes:
found = False
for i, n in enumerate(nums):
if colors[i] == 0 and p in numf[i]:
if not found:
found = True
c += 1
colors[i] = c
print(c)
print(*colors)
tt = int(input())
for _ in range(tt):
solve() | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | T = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(T):
n, co = int(input()), list(map(int, input().split()))
color, vis = [0] * n, {}
for i in range(n):
for j in range(11):
if co[i] % p[j] == 0:
if j not in vis.keys():
vis[j] = len(vis)
color[i] = j
break
color = [(vis[u] + 1) for u in color]
print(len(vis))
print(*color) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for i in range(t):
a = int(input())
l = list(map(int, input().split()))
d = []
c = []
m = []
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for j in l:
for k in p:
if j % k == 0:
if k in d:
c.append(d.index(k) + 1)
else:
d.append(k)
c.append(d.index(k) + 1)
if p.index(k) not in m:
m.append(p.index(k))
break
print(len(m))
print(*c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in " " * int(input()):
n = int(input())
a = list(map(int, input().split()))
lst = [0] * n
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
color = 1
for i in range(15):
f = 0
for j in range(n):
if lst[j] == 0:
if a[j] % prime[i] == 0:
lst[j] = color
f = 1
if f == 1:
color += 1
print(len(set(lst)))
print(*lst) | FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | a = int(input())
for _ in range(a):
b = int(input())
c = [int(i) for i in input().split()]
d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
e = []
ans = []
for i in c:
for j in d:
if i % j == 0:
if not j in e:
ans.append(str(len(e) + 1))
e.append(j)
else:
ans.append(str(e.index(j) + 1))
break
print(len(e))
print(" ".join(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def primes(c):
primes = []
p = 2
while c >= p * p:
if c % p == 0:
primes.append(p)
c = c // p
elif p == 2:
p += 1
else:
p += 2
if c != 1:
primes.append(c)
return primes
def pick(map, c):
if not c in map:
map[c] = len(map) + 1
return map[c]
T = int(input())
for _ in range(T):
N = int(input())
numbers = list(map(int, input().split()))
solution = []
colors = {}
for num in numbers:
pms = primes(num)
if 2 in pms:
solution.append(pick(colors, 1))
elif 3 in pms:
solution.append(pick(colors, 2))
elif 5 in pms:
solution.append(pick(colors, 3))
elif 7 in pms:
solution.append(pick(colors, 4))
elif 11 in pms:
solution.append(pick(colors, 5))
elif 13 in pms:
solution.append(pick(colors, 6))
elif 17 in pms:
solution.append(pick(colors, 7))
elif 19 in pms:
solution.append(pick(colors, 8))
elif 23 in pms:
solution.append(pick(colors, 9))
elif 29 in pms:
solution.append(pick(colors, 10))
elif 31 in pms:
solution.append(pick(colors, 11))
print(len(colors))
print(" ".join(map(str, solution))) | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | import sys
ea = 1001
prime_numbers = [True] * ea
for i in range(2, int(ea**0.5) + 1):
if prime_numbers[i] == True:
for j in range(i * 2, ea, i):
prime_numbers[j] = False
prime = []
for i in range(2, int(ea**0.5) + 1):
if prime_numbers[i] == True:
prime.append(i)
composite_numbers = [0] * ea
color = 1
for p in prime:
for i in range(p * 2, ea, p):
composite_numbers[i] = color
color += 1
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
res = []
for i in c:
res.append(composite_numbers[i])
color = 0
for r in sorted(list(set(res))):
color += 1
for i in range(len(res)):
if res[i] == r:
res[i] = color
print(color)
print(*res) | IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | import sys
input = sys.stdin.buffer.readline
first11Primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def getSmallestPrimeFactor(x):
for p in first11Primes:
if x % p == 0:
return p
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
ans = [(-1) for __ in range(n)]
mapp = dict()
j = 1
for i in range(n):
p = getSmallestPrimeFactor(a[i])
if p not in mapp.keys():
mapp[p] = j
j += 1
ans[i] = mapp[p]
print(j - 1)
print(" ".join([str(x) for x in ans])) | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | x = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
m = [0] * n
for i in range(n):
for j in range(len(x)):
if l[i] % x[j] == 0:
m[i] = j + 1
s = set(m)
print(len(s))
d = {x: y for y, x in enumerate(s, 1)}
for i in m:
print(d[i], end=" ")
print() | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | I = lambda: list(map(int, input().split()))
p = [0] * 501
pr = []
for i in range(2, 501):
n = i
for j in range(2, int(n**0.5) + 1):
if n % j == 0:
break
else:
p[i] = 1
pr.append(i)
for _ in range(int(input())):
(n,) = I()
l = I()
c = [0] * n
ck = [0] * 11
k = 1
for i in range(n):
if l[i]:
for x in range(11):
if l[i] % pr[x] == 0:
if ck[x] == 0:
ck[x] = k
k += 1
c[i] = ck[x]
break
print(max(c))
print(*c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def getpos(li, e):
s = len(li)
for i in range(s):
if li[i] == e:
return i + 1
a = [1] * 33
a[0] = a[1] = 0
for i in range(2, 6):
if a[i] == 1:
for j in range(i * i, 33, i):
a[j] = 0
prime = []
for i in range(33):
if a[i] == 1:
prime.append(i)
t = int(input())
for l in range(t):
n = int(input())
li = list(map(int, input().split()))
an = [0] * n
for j in range(0, len(prime)):
for i in range(n):
if li[i] % prime[j] == 0 and an[i] == 0:
an[i] = j + 1
us = len(set(an))
tl = list(set(an))
print(us)
for e in an:
print(getpos(tl, e), end=" ")
print() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
sin_usar = []
usar = []
primos = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
dif = []
mostrar = []
for i in range(0, t):
c = int(input())
d = input()
b = ""
for i in range(0, c):
sin_usar.append(d.split(" ")[i])
for i in range(0, c):
for j in range(0, len(primos)):
if int(sin_usar[i]) % int(primos[j]) == 0:
sin_usar[i] = int(primos[j])
for i in sin_usar:
if i not in dif:
dif.append(i)
for i in range(0, len(sin_usar)):
for j in range(0, len(dif)):
if sin_usar[i] == dif[j]:
usar.append(j + 1)
for i in range(0, len(usar)):
b += str(usar[i]) + " "
mostrar.append(len(dif))
mostrar.append(b)
sin_usar = []
usar = []
dif = []
for i in range(0, len(mostrar)):
print(mostrar[i]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
checked = [0] * n
col = 1
cnt = 0
for p in primes:
if cnt > 0:
col += 1
cnt = 0
for j in range(n):
if not checked[j]:
if l[j] % p == 0:
cnt += 1
checked[j] = col
print(max(checked))
print(*checked) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31
def algo(inp, n):
result = []
colors = [None] * 11
for i in range(n):
for j in range(11):
if inp[i] % primes[j] == 0:
result.append(j + 1)
colors[j] = True
break
print(colors.count(True))
print(*[(i - colors[: i - 1].count(None)) for i in result])
for _ in range(int(input())):
n = int(input())
inp = list(map(int, input().split()))
algo(inp, n) | ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NONE VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | import sys
t = int(input())
inp = [line.strip().split() for line in reversed(sys.stdin.readlines())]
ans = []
markers = []
simple_numbers = []
for i in range(2, 100):
flag = True
j = 2
while j * j <= i:
if i % j == 0:
flag = False
break
j += 1
if flag:
simple_numbers.append(i)
while t:
n = int(inp[-1][0])
a = [int(i) for i in inp[-2]]
markers = [0] * n
used_count = 1
prev_used = False
for simp in simple_numbers:
if not all(markers):
if prev_used:
used_count += 1
numbers_colored = 0
for ind_an, an in enumerate(a):
if an % simp == 0 and markers[ind_an] == 0:
markers[ind_an] = used_count
prev_used = True
numbers_colored += 1
if numbers_colored == 0:
prev_used = False
else:
break
print(used_count)
print(*markers)
inp.pop()
inp.pop()
t -= 1 | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | T = int(input())
for _ in range(T):
n = int(input())
a = list(map(int, input().split()))
color = [0] * n
m = 0
setup = set()
def run(x):
global m
for i in range(n):
if not color[i] and a[i] % x == 0:
color[i] = m + 1
setup.add(x)
if x in setup:
m += 1
for d in range(2, 32):
run(d)
for i in range(n):
if color[i] == 0:
color[i] = m + 1
m += 1
print(m)
print(" ".join(map(str, color))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
a = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
n = int(input())
ans = []
count = 0
dict = {}
l = [int(i) for i in input().split()]
for u, e in enumerate(l):
for f in a:
if e % f == 0:
if f not in dict:
dict[f] = [u]
count += 1
break
else:
dict[f].append(u)
break
var = 1
for e in dict.values():
for x in e:
l[x] = var
var += 1
print(count)
print(*l) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
n = int(input())
mapped = {p: [] for p in primes}
arr = list(map(int, input().split()))
for i in range(n):
for p in primes:
if arr[i] % p == 0:
mapped[p].append(i)
id_color = 0
colored = [0] * n
for p, idxs in mapped.items():
if len(idxs) > 0:
id_color += 1
is_used = False
for idx in idxs:
if colored[idx] == 0:
is_used = True
colored[idx] = id_color
if not is_used:
id_color -= 1
print(max(colored))
for i in range(n):
if i != n - 1:
print(colored[i], end=" ")
else:
print(colored[i]) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
numbers = []
for i in range(1000):
numbers.append(i + 1)
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
div = {}
for i in primes:
for j in numbers:
if j % i == 0:
div[j] = i
numbers.remove(j)
for i in range(t):
group = []
pairs = {}
n = int(input())
a = list(map(int, input().split()))
for j in range(n):
v = pairs.get(div[a[j]], 0)
if v == 0:
pairs[div[a[j]]] = len(pairs) + 1
v = len(pairs)
group.append(v)
output = " ".join(map(str, group))
print(len(set(group)))
print(output) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
temp = {
(2): 12,
(3): 12,
(5): 12,
(7): 12,
(11): 12,
(13): 12,
(17): 12,
(19): 12,
(23): 12,
(29): 12,
(31): 12,
}
count = 1
ans = []
for i in c:
for j in temp:
if i % j == 0:
if temp[j] == 12:
temp[j] = count
count += 1
ans.append(temp[j])
break
print(count - 1)
print(*ans, sep=" ") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def sieve():
plist = [2]
for i in range(3, 500, 2):
prime = True
for p in plist:
if i % p == 0:
prime = False
break
if prime:
plist.append(i)
return plist
def pair(plist, lim=1000):
plistcpy = list(plist)
pairs = []
while len(plistcpy) > 0:
p1 = plistcpy[0]
p2 = plistcpy[-1]
while p1 * p2 > 1000 and len(plistcpy) > 0:
plistcpy.pop()
p2 = plistcpy[-1]
if p1 * p2 <= 1000:
pairs.append([p1, p2])
plistcpy.pop(0)
return pairs
def flatten(colors):
unique = list(set(colors))
number = len(unique)
mapping = {c: (n + 1) for n, c in enumerate(unique)}
colors = [mapping[col] for col in colors]
return number, colors
T = int(input())
plist = sieve()
pairs = pair(plist)
testprimes = [pair[0] for pair in pairs]
for test in range(T):
N = int(input())
Alist = list(map(int, input().split()))
colors = [(0) for a in Alist]
for n, a in enumerate(Alist):
for i, p in enumerate(testprimes):
if a % p == 0:
colors[n] = i + 1
break
number, colors = flatten(colors)
print(number)
for color in colors:
print(color) | FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
ans = [-1] * n
curr_col = 1
for p in prime:
got = 0
for i in range(n):
if ans[i] != -1:
continue
if arr[i] % p != 0:
continue
got = 1
ans[i] = curr_col
if got == 1:
curr_col += 1
print(curr_col - 1)
for i in ans:
print(i, end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def simple_nums(n):
lst = [(True) for x in range(n + 1)]
lst[0] = False
lst[1] = False
for i in range(len(lst)):
if lst[i]:
for k in range(i * 2, len(lst), i):
lst[k] = False
lst2 = []
for i in range(len(lst)):
if lst[i]:
lst2.append(i)
return lst2
def main():
lst1 = simple_nums(500)
n = int(input())
lst = list(map(int, input().split()))
cols = [(0) for _ in range(n)]
used = set()
for i in range(n):
for k in range(11):
if lst[i] % lst1[k] == 0:
cols[i] = k + 1
used.add(k + 1)
break
dct = dict()
m = 1
for i in used:
dct[i] = m
m += 1
print(len(used))
for i in cols:
print(dct[i], end=" ")
print()
t = int(input())
for i in range(t):
main() | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for x in range(int(input())):
n = int(input())
li = list(map(int, input().split()))
lis = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
ali = []
ma = {}
ans = 0
for i in li:
for j in lis:
if i % j == 0:
try:
ali.append(ma[j])
break
except:
ma[j] = ans + 1
ans = ans + 1
ali.append(ma[j])
break
print(ans)
print(*ali, sep=" ") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
col = 0
ans = []
di = {
(2): 0,
(3): 0,
(5): 0,
(7): 0,
(11): 0,
(13): 0,
(17): 0,
(19): 0,
(23): 0,
(29): 0,
(31): 0,
}
for i in l:
for j in di:
if i % j == 0:
if di[j] == 0:
col += 1
di[j] = col
ans.append(di[j])
break
print(col)
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for case in range(t):
n = int(input())
a = [int(x) for x in input().split(" ")]
ans = []
for c in a:
for i in range(11):
if c % primes[i] == 0:
ans.append(i + 1)
break
m = len(set(ans))
print(m)
for i in range(1, m + 1):
if i not in ans:
z = max(ans)
ans = [(j + int(j == z) * (i - j)) for j in ans]
print(*ans) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
q = int(input())
s = list(map(int, input().split()))
colors = []
ans = []
for n in s:
i = 0
while i < len(colors) and n % colors[i]:
i += 1
if i < len(colors):
ans.append(i + 1)
else:
i = 2
while n % i:
i += 1
colors.append(i)
ans.append(len(colors))
print(len(colors))
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
primes = list(range(2, 1003))
for i in range(2, int(1002**0.5) + 1):
if i in primes:
j = i * i
while j <= 1002:
try:
primes.remove(j)
except:
pass
j += i
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
track = 1
for i in primes:
flag = 0
for j in range(n):
if a[j] % i == 0:
if b[j] == 0:
b[j] = track
flag = 1
if flag:
track += 1
if b.count(0) == 0:
break
print(len(list(set(b))))
print(*b) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
color = [0] * n
for i in range(n):
for j in range(2, 32):
if l[i] % j == 0:
color[i] = j
break
dic = {}
count = 1
for i in range(n):
if dic.get(color[i]) == None:
dic[color[i]] = count
color[i] = count
count += 1
else:
color[i] = dic[color[i]]
print(len(dic))
print(*color, sep=" ") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def SieveOfErathosthenes(n=1000):
prime = [1] * (n + 1)
res = [[] for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p]:
for i in range(2 * p, n + 1, p):
prime[i] = 0
res[i].append(p)
p += 1
return res
def solve(a):
c = [0] * len(a)
m = set()
for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
for j in range(len(a)):
if a[j] % p == 0 and c[j] == 0:
if p not in m:
m.add(p)
c[j] = len(list(m))
print(len(list(m)))
print(" ".join([str(e) for e in c]))
t = int(input())
for _ in range(t):
n = int(input())
a = [int(i) for i in input().split()]
solve(a) | FUNC_DEF NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def solve(a):
c = [0] * len(a)
m = []
for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
for j in range(len(a)):
if a[j] % p == 0 and c[j] == 0:
if p not in m:
m.append(p)
c[j] = len(m)
print(len(m))
print(" ".join([str(e) for e in c]))
t = int(input())
for _ in range(t):
n = int(input())
a = [int(i) for i in input().split()]
solve(a) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def is_used(prime):
for i in range(len(used)):
if prime == used[i]:
return i
return -1
T = int(input())
for _ in range(T):
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
used = []
n = int(input())
c = 0
arr = [int(x) for x in input().split()]
for i in range(n):
for j in range(11):
if arr[i] % p[j] == 0:
ind = is_used(p[j])
if ind < 0:
c += 1
arr[i] = c
used.append(p[j])
break
else:
arr[i] = ind + 1
break
print(c)
for x in arr:
print(x, end=" ") | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def smallestDivisor(n):
if n % 2 == 0:
return 2
i = 3
while i * i <= n:
if n % i == 0:
return i
i += 2
return n
for i in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
list_of_color = []
for i in a:
list_of_color.append(smallestDivisor(i))
list_of_color = list(set(list_of_color))
string = ""
for i in range(len(a)):
for j in range(len(list_of_color)):
if smallestDivisor(a[i]) == list_of_color[j]:
string = string + str(j + 1) + " "
print(len(list_of_color))
print(string) | FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def solve(nums, n):
prime_dict = {p: [] for p in primes}
colors = [0] * n
largest_color = 0
for ind, num in enumerate(nums):
for p in primes:
if num < p:
break
if num % p == 0:
if prime_dict[p]:
prime_dict[p].append(ind)
colors[ind] = colors[prime_dict[p][0]]
else:
prime_dict[p].append(ind)
largest_color += 1
colors[ind] = largest_color
break
return largest_color, colors
t = int(input())
for _ in range(t):
n = int(input())
nums = list(map(int, input().split()))
m, result = solve(nums, n)
print(m)
print(" ".join(map(str, result))) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | pr = []
for i in range(2, 500):
for j in range(2, i):
if i % j == 0:
break
else:
pr.append(i)
t = int(input())
for q in range(t):
m = 0
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(len(a)):
if a[i] == 0:
continue
for j in pr:
if a[i] % j != 0:
continue
a[i] = 0
m += 1
ans[i] = m
for k in range(i + 1, n):
if a[k] % j == 0 and a[k] != 0:
ans[k] = m
a[k] = 0
break
print(m)
print(*ans) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
elem = [0] * n
check = [False] * 11
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(n):
for j in range(11):
if a[i] % primes[j] == 0:
elem[i] = primes[j]
check[j] = True
break
m = 0
i = 0
while i < len(primes):
if not check[i]:
primes.pop(i)
check.pop(i)
else:
i = i + 1
di = {}
print(len(primes))
for i in range(len(primes)):
di[primes[i]] = i + 1
for i in elem:
print(di[i], end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | from sys import stdin
def sieve_of_eratosthenes(n):
all_prime = []
prime = [(True) for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p]:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
for p in range(2, n):
if prime[p]:
all_prime.append(p)
return all_prime
all_primes = sieve_of_eratosthenes(int(1000**0.5) + 1)
for _ in range(int(input())):
n = int(stdin.readline().rstrip())
l = list(map(int, stdin.readline().rstrip().split(" ")))
x = set()
t = 0
r = {}
for i in range(n):
for j in range(len(all_primes)):
if l[i] % all_primes[j] == 0:
a = r.get(j, 0)
if a:
l[i] = a
else:
l[i] = t + 1
t += 1
r[j] = t
break
print(t)
print(*l) | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def colorize(n):
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for p in range(len(primes)):
if n % primes[p] == 0:
return p
t = int(input())
for test in range(t):
n = int(input())
lst = [int(i) for i in input().split()]
ans = [colorize(i) for i in lst]
conv = list(set(ans))
print(len(conv))
anticonv = [(0) for i in range(12)]
for it in range(len(conv)):
anticonv[conv[it]] = it
realans = [str(anticonv[i] + 1) for i in ans]
print(" ".join(realans)) | FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def find_nod(number):
i = 2
while i <= number:
if number % i == 0:
return i
i += 1
t = int(input())
for i in range(t):
n = int(input())
numbers = [int(i) for i in input().split()]
output = [(0) for i in numbers]
n_colors = 0
divs = []
for j, number in enumerate(numbers):
flag = 0
for k, div in enumerate(divs):
if number % div == 0:
flag = 1
output[j] = k + 1
if flag == 0:
n_colors += 1
divs.append(find_nod(number))
output[j] = len(divs)
print(n_colors)
print(*output, sep=" ") | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
parr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
oarr = []
carr = []
n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
for j in range(11):
if arr[i] % parr[j] == 0:
oarr += [parr[j]]
if parr[j] not in carr:
carr += [parr[j]]
break
print(len(carr))
carr.sort()
for i in range(len(oarr)):
print(carr.index(oarr[i]) + 1, end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR LIST VAR VAR IF VAR VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for i in range(t):
n = int(input())
a = input().split()
for j in range(n):
a[j] = int(a[j])
s = []
s.append(2)
s.append(3)
s.append(5)
s.append(7)
s.append(11)
s.append(13)
s.append(17)
s.append(19)
s.append(23)
s.append(29)
s.append(31)
c = []
for j in range(11):
c.append(0)
f = []
for j in range(n):
for k in range(11):
if a[j] % s[k] == 0:
c[k] += 1
break
m = 0
p = []
for j in range(11):
if c[j] != 0:
p.append(s[j])
m += 1
for j in range(n):
for k in range(m):
if a[j] % p[k] == 0:
f.append(k + 1)
break
print(m)
for j in range(n):
print(f[j], end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | from sys import stdin
for _ in range(int(stdin.readline())):
n = int(stdin.readline())
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
l = [[] for _ in range(11)]
arr = list(map(int, stdin.readline().split()))
ans = [0] * n
for x in range(n):
for d in range(11):
if arr[x] % pr[d] == 0:
l[d].append(x)
break
j = 1
for x in range(11):
for d in l[x]:
ans[d] = j
if len(l[x]):
j += 1
print(max(ans))
for r in ans:
print(r, end=" ")
print("") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for iii in range(t):
n = int(input())
m = list(map(int, input().split()))
ans = [0] * n
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
cv = []
for i in range(11):
cv.append([])
for i in range(n):
for j in range(11):
if m[i] % pr[j] == 0:
cv[j].append(i)
break
v = []
for i in cv:
if len(i) > 0:
v.append(i)
for i in range(len(v)):
for j in v[i]:
ans[j] = i + 1
ansk = max(ans)
print(ansk)
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
x = [2, 3, 5, 7, 11]
d = {}
y = [1, 4, 6, 8, 9, 10]
z = [13, 17, 19, 23, 29, 31]
ans = []
k = 1
for i in range(n):
for j in range(5):
if a[i] % x[j] == 0:
if x[j] not in d:
d[x[j]] = k
k += 1
ans.append(d[x[j]])
break
else:
for j in range(6):
if a[i] % z[j] == 0:
if z[j] not in d:
d[z[j]] = k
k += 1
ans.append(d[z[j]])
break
print(max(ans))
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | from sys import stdin, stdout
input = stdin.readline
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = max(a)
prime = [(1) for i in range(b + 1)]
i = 2
while i * i <= b:
if prime[i] == 1:
for j in range(i * i, b + 1, i):
if prime[j] == 1:
prime[j] = i
i += 1
c = {}
for i in range(n):
if c.get(prime[a[i]]) == None:
c[prime[a[i]]] = [i]
else:
c[prime[a[i]]].append(i)
m = 0
ans = [(0) for i in range(n)]
for i in c:
m += 1
for j in c[i]:
ans[j] = m
print(m)
print(*ans) | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NONE ASSIGN VAR VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | prime = []
for i in range(2, 32):
temp = True
for j in range(2, i // 2 + 1):
if i % j == 0:
temp = False
break
else:
continue
if temp:
prime.append(i)
x = int(input())
for i in range(x):
y = int(input())
ans = [0] * 11
temp1 = list(map(int, input().split()))
temp2 = []
temp3 = 0
temp4 = 1
for j in temp1:
for k in range(11):
if j % prime[k] == 0:
if ans[k] == 0:
ans[k] = temp4
temp4 += 1
temp2.append(str(ans[k]))
break
for i in ans:
if i != 0:
temp3 += 1
print(temp3)
print(" ".join(temp2)) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def isPrime(n):
i = 2
while i * i <= n:
if n % i == 0:
return False
i += 1
return True
prime = [2]
for i in range(3, 1000, 2):
if isPrime(i):
prime.append(i)
l = [i for i in range(4, 1001) if i not in prime]
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = {}
col = -1
cnt = 0
for p in prime[:11]:
flag = 0
for i in range(n):
if a[i] > 0:
if a[i] % p == 0:
a[i] = col
cnt += 1
flag = 1
if cnt == n:
break
if flag:
col -= 1
if cnt < n:
for i in range(n):
if a[i] > 0:
a[i] = col
col -= 1
col += 1
col = abs(col)
print(col)
for i in range(n):
a[i] = abs(a[i])
print(*a) | FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31
T = int(input())
while T > 0:
n = int(input())
arr = map(int, input().split())
ans = []
mp = {}
cnt = 1
for num in arr:
for p in primes:
if num % p == 0:
ans.append(p)
if p not in mp:
mp[p] = cnt
cnt += 1
break
print(len(mp))
for i in ans:
print(mp[i], end=" ")
print()
T -= 1 | ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for ii in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
ans = []
ind = 0
flag = [0] * 13
c = 0
for i in range(n):
for j in range(len(prime)):
if arr[i] % prime[j] == 0:
if flag[j] == 0:
ind += 1
flag[j] = ind
ans.append(ind)
else:
ans.append(flag[j])
break
print(ind)
print(*ans) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def get_primes(k):
p = [True] * (k + 1)
p[0] = False
p[1] = False
for i in range(1, k + 1):
if p[i]:
for j in range(2, k // i + 1):
p[i * j] = False
pr = []
for i in range(k + 1):
if p[i]:
pr.append(i)
return pr
p = get_primes(1001)
t = int(input())
for test in range(t):
n = int(input())
a = list(map(int, input().split()))
b = [None] * n
k = 1
flag = False
for x in p:
for z in range(n):
if b[z] is None and a[z] % x == 0:
b[z] = k
flag = True
if flag:
k += 1
flag = False
print(k - 1)
for x in b:
print(x, end=" ")
print() | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().rstrip().split()))
l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
d = {}
chk = {}
t = 1
for i in range(len(a)):
for j in range(len(l)):
if a[i] % l[j] == 0:
d[i] = j + 1
if j + 1 not in chk:
chk[j + 1] = t
t += 1
break
print(len(chk))
for i in range(n):
print(chk[d[i]], end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | from sys import stdin, stdout
t = int(stdin.readline().strip())
P = {a: (0) for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]}
for _ in range(t):
n = int(stdin.readline().strip())
alist = list(map(int, stdin.readline().split()))
for p in P:
P[p] = 0
used = 0
ans = []
for a in alist:
for p in P:
if a % p == 0 or p == 31:
if P[p] == 0:
used += 1
P[p] = used
ans.append(p)
break
ans = " ".join([str(P[a]) for a in ans])
stdout.write("{}\n{}\n".format(used, ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def first_factor(x):
for p in primes:
if x % p == 0:
return p
return 0
t = int(input())
output = ""
for i in range(t):
m = 0
factors = []
tuples = []
res = ""
n = int(input())
A = [int(x) for x in input().split(" ")]
for j in range(n):
p = first_factor(A[j])
if p not in factors:
factors.append(p)
m += 1
res += str(m) + " "
else:
res += str(factors.index(p) + 1) + " "
output += str(m) + "\n" + res + "\n"
print(output) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
n = int(input())
m = 0
a = []
c = {}
for x in map(int, input().split()):
for i, d in enumerate(p):
if 0 == x % d:
a += (i,)
c[i] = 0
break
for i, x in enumerate(c):
c[x] = i + 1
print(len(c))
a = [c[x] for x in a]
print(*a) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
while t != 0:
n = int(input())
A = list(map(int, input().split()))
d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
res = [0] * n
i = 0
while i < 11:
j = 0
while j < n:
if A[j] % d[i] == 0:
res[j] = i + 1
j += 1
i += 1
x = len(set(res))
B = [1]
l = 1
k = 1
while k < n:
if res[k] not in res[:k]:
l += 1
B.append(l)
else:
B.append(B[res.index(res[k])])
k += 1
print(x)
print(*B)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(t):
n = int(input())
nums = list(map(int, input().split()))
sol = [(0) for k in range(n)]
for i in range(n):
for j in range(11):
if nums[i] % primes[j] == 0:
sol[i] = j + 1
break
print(len(set(sol)))
groups = {}
k = 0
for s in sol:
if s not in groups:
k += 1
groups[s] = k
print(k, end=" ")
else:
print(groups[s], end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def slv(a):
cd = {}
ans = []
for i in a:
for pp in p:
if i % pp == 0:
if pp not in cd:
cd[pp] = len(cd) + 1
ans.append(cd[pp])
break
print(len(cd))
print(" ".join([str(i) for i in ans]))
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
slv(a) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | from sys import stdin
input = iter(stdin.readlines()).__next__
spf = [(i if i % 2 == 1 else 2) for i in range(0, 1001)]
for i in range(3, 32, 2):
if spf[i] == i:
for j in range(i * i, 1001, i):
if spf[j] == j:
spf[j] = i
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
spfs = list(map(lambda x: spf[x], a))
m = list(set(spfs))
c = list(map(lambda x: m.index(x) + 1, spfs))
print(len(m))
print(*c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | lcd = [(0) for k in range(1001)]
for k in range(1, 1001):
for p in range(2, k + 1):
if k % p == 0:
lcd[k] = p
break
for t in range(int(input())):
n = int(input())
ar = [int(x) for x in input().split()]
s = set()
for k in range(n):
s.add(lcd[ar[k]])
ar[k] = lcd[ar[k]]
print(len(s))
s = list(s)
s.sort()
d = {}
ctr = 1
for k in s:
d[k] = ctr
ctr += 1
for k in ar:
print(d[k], end=" ")
print() | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
dct = {}
m = 1
arr1 = []
for n1 in arr:
check = -1
n2 = int(n1**0.5)
for j in range(2, n2 + 1, 1):
if n1 % j == 0:
check = 0
if j in dct.keys():
arr1.append(dct[j])
else:
dct[j] = m
arr1.append(m)
m += 1
break
if check == -1:
dct[n1] = m
arr1.append(m)
m += 1
print(m - 1)
for i in arr1:
print(i, end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def factor(n):
for i in range(2, n + 1):
if n % i == 0:
return i
return n
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
colors = [(0) for i in range(11)]
current = 0
ans = []
for i in a:
found = 0
for j in range(current):
if i % colors[j] == 0:
ans.append(j + 1)
found = 1
break
if not found:
colors[current] = factor(i)
ans.append(current + 1)
current += 1
print(len(set(ans)))
print(*ans) | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | def sieve(n):
a = [1] * (n + 1)
a[0] = a[1] = 0
i = 2
while i * i <= n:
if a[i]:
j = i * i
while j <= n:
a[j] = 0
j += i
i += 1
return a
for _ in range(int(input())):
p = sieve(40)
n = int(input())
a = list(map(int, input().split()))
b = []
for x in a:
for i in range(2, 41):
if x % i == 0:
b.append(i)
p[i] += 1
break
m = 1
for i in range(41):
if p[i] > 1:
p[i] = m
m += 1
b = [p[x] for x in b]
print(m - 1)
print(*b) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m 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 1, i.e. \gcd(a_i, a_j)>1 for each pair i, 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 m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 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 m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 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 n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-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 m from 1 to 11.
Remember that each color from 1 to m 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 1).
Example
Input
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
Output
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
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \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. | t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
k = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
r = []
for i in range(n):
for j in range(11):
if l[i] % k[j] == 0:
r.append(j + 1)
break
p = set(r)
print(len(p))
d = {x: y for y, x in enumerate(p, 1)}
for i in r:
print(d[i], end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.