description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
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. | arr = [0] * 1000
A = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(0, 1000):
j = 0
while j < len(A):
if (i + 1) % A[j] > 0:
j = j + 1
else:
break
arr[i] = j
i = i + 1
n = int(input())
while n > 0:
ans = []
m = -int(input())
quest = [int(i) for i in input().split()]
while m < 0:
ans += [arr[quest[m] - 1]]
m = m + 1
L = list(enumerate(set(ans)))
dic = {y: (x + 1) for x, y in L}
R = [dic[x] for x in ans]
print(max(R))
print(" ".join([str(i) for i in R]))
n = n - 1 | 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 NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER VAR LIST VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN 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 VAR ASSIGN VAR BIN_OP 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. | for h in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
div = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
colours = [0] * n
for i in range(n):
for j in div:
if a[i] % j == 0:
colours[i] = j
break
cnt = [0] * 11
for i in colours:
cnt[div.index(i)] = 1
cur = 0
for j in range(11):
if cnt[j] == 1:
cur += 1
for i in range(n):
if colours[i] == div[j]:
colours[i] = cur
print(max(colours))
print(*colours) | 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 FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR 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. | t = int(input())
r = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
while t:
t -= 1
n = int(input())
a = list(map(int, input().split()))
ind = dict()
cc = 0
r1 = [1] * n
for i in range(n):
for j in range(11):
if a[i] % r[j] == 0:
if r[j] not in ind:
ind[r[j]] = cc + 1
cc += 1
r1[i] = ind[r[j]]
break
print(max(r1))
print(*r1) | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR 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 gettrace, stdin
if not gettrace():
def input():
return next(stdin)[:-1]
def main():
def solve():
n = int(input())
aa = [int(a) for a in input().split()]
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
used = [False] * 11
cn = [-1] * n
for i, a in enumerate(aa):
for j, p in enumerate(primes):
if a % p == 0:
cn[i] = j
used[j] = True
break
nc = 1
cmap = [-1] * 11
for i, u in enumerate(used):
if u:
cmap[i] = nc
nc += 1
res = map(lambda c: str(cmap[c]), cn)
print(nc - 1)
print(" ".join(res))
q = int(input())
for _ in range(q):
solve()
main() | IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FUNC_DEF 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR 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. | def divides(a, b):
if b % a == 0:
return True
return False
def primeDivide(a):
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in primes:
if divides(i, a):
return i
def coloring(seq):
colors = {}
ret = ""
m = 0
for i in seq:
poop = primeDivide(i)
if poop in colors:
ret = ret + str(colors[poop]) + " "
else:
m += 1
colors[poop] = m
ret = ret + str(m) + " "
return ret[0:-1], m
trials = input("")
output = []
for j in range(int(trials)):
input("")
a, b = coloring([int(i) for i in input("").split(" ")])
output.append(b)
output.append(a)
for i in output:
print(i) | FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING RETURN VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING EXPR 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. | t = int(input())
output = []
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = [0] * len(a)
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,
]
colors = {}
n = 1
for i in range(len(a)):
for j in range(len(primes)):
if a[i] % primes[j] == 0:
if primes[j] not in colors:
colors[primes[j]] = n
n += 1
b[i] = colors[primes[j]]
break
s = str(b[0])
for i in range(1, len(b)):
s += " " + str(b[i])
output.append(str(max(b)))
output.append(s)
for o in output:
print(o) | 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 ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR 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 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 IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL 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. | t = int(input())
d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(t):
dic = dict()
n = int(input())
a = list(map(int, input().split()))
ans = []
s = set()
for i in a:
for j in d:
if i % j == 0:
if j not in dic:
dic[j] = len(dic) + 1
ans.append(dic[j])
s.add(j)
break
print(len(s))
for i in ans:
print(i, 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 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 FUNC_CALL VAR 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 VAR 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. | simple = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def find_colour(x, used):
for i in range(len(simple)):
if x % simple[i] == 0:
if i in used:
return str(used[i])
else:
used[i] = len(used) + 1
return str(used[i])
def solve():
amount = int(input())
nums = list(map(int, input().split()))
ans = []
used = dict()
for num in nums:
ans.append(find_colour(num, used))
print(len(used))
print(" ".join(ans))
n = int(input())
for i in range(n):
solve() | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR 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 LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. | ttt = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for qqq in range(ttt):
n = int(input())
a = list(map(int, input().split()))
c = [0] * 11
mask = [False] * 11
for k in range(n):
for i in range(11):
if a[k] % primes[i] == 0:
a[k] = i
mask[i] = True
break
k = 0
for i in range(11):
if mask[i]:
k += 1
c[i] = k
print(k)
for x in a:
print(c[x], 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 BIN_OP LIST NUMBER NUMBER 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 ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER 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. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
result = [0] * n
k = 1
flag = False
for div in range(2, 32):
for i in range(n):
if a[i] and a[i] % div == 0:
result[i] = k
a[i] = 0
flag = True
if flag:
k += 1
flag = False
print(k - 1)
print(*result) | 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER 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. | def newf(x):
for i in range(2, int(x ** (1 / 2) + 1)):
if x % i == 0:
return i
def composite(n, a):
colorsdic = {}
colors = []
for x in a:
i = newf(x)
if i in colorsdic:
colors.append(colorsdic[i])
else:
colorsdic[i] = len(colorsdic) + 1
colors.append(colorsdic[i])
print(len(colorsdic))
for p in colors:
print(p, end=" ")
print()
return
t = int(input())
array = []
for i in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
array.append([n, a])
for x in array:
composite(*x) | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR 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 FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR RETURN 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 STRING EXPR FUNC_CALL VAR LIST 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. | kount = int(input())
for _ in range(kount):
ans = []
smth = {}
garbage = int(input())
arr = list(map(int, input().split()))
now_counter = 0
def find_min_del(x: int):
i = 1
while i <= x:
i += 1
if x % i == 0:
return i
for i in range(0, len(arr)):
min_del_now = find_min_del(arr[i])
if min_del_now not in smth:
now_counter += 1
smth[min_del_now] = now_counter
ans.append(smth[min_del_now])
print(len(smth))
for i in range(len(ans)):
print(ans[i], end=" ")
print("\n") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER FUNC_DEF VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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. | from sys import stdin
inp = stdin.readline
t = int(inp().strip())
for i in range(t):
n = int(inp().strip())
array = [int(x) for x in inp().strip().split()]
primeNumbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
d = {}
colorArray = [-1] * n
usedCounter = 1
for j in range(n):
for k in range(11):
if array[j] % primeNumbers[k] == 0:
if d.get(primeNumbers[k], 0) == 0:
d[primeNumbers[k]] = usedCounter
usedCounter += 1
colorArray[j] = d[primeNumbers[k]]
break
print(usedCounter - 1)
print(*colorArray) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR 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. | import sys
input = sys.stdin.readline
for j in range(int(input())):
n = int(input())
a = list(map(int, input().split(" ")))
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
currCol = 1
colorMap = {}
ans = 1
for x in primes:
inc = False
for m in a:
if m % x == 0 and m not in colorMap:
colorMap[m] = currCol
ans = currCol
inc = True
if inc == True:
currCol = currCol + 1
print(ans)
coloring = [str(colorMap[f]) for f in a]
print(" ".join(coloring)) | IMPORT 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 STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR 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. | from sys import stdin
input = stdin.readline
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
l = [0] * 11
ll = [0] * 11
for x in a:
for y in range(11):
if x % p[y] == 0:
l[y] += 1
break
xx = 1
for x in range(11):
if l[x] != 0:
ll[x] = xx
xx += 1
print(xx - 1)
for x in a:
for y in range(11):
if x % p[y] == 0:
print(ll[y], end=" ")
break
print() | ASSIGN VAR VAR 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER 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. | import sys
RI = lambda: [int(x) for x in sys.stdin.readline().split()]
ri = lambda: sys.stdin.readline().strip()
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("Yes")
def NO():
print("No")
INF = 10**18
MOD = 10**9 + 7
def seive():
p = 2
while p * p < 1001:
if prime[p]:
for i in range(p * p, 1001, p):
if prime[i]:
prime[i] = not prime[i]
sp[i] = p
p += 1
for _ in range(int(ri())):
n = int(ri())
a = RI()
sp = [i for i in range(1001)]
prime = [True] * 1001
seive()
ite = 1
dic = {}
ans = [0] * n
for i in range(len(a)):
if sp[a[i]] in dic:
ans[i] = dic[sp[a[i]]]
else:
dic[sp[a[i]]] = ite
ans[i] = ite
ite += 1
print(ite - 1)
print(*ans) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR 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 ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER 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. | def gcd(a, b):
if a < b:
return gcd(b, a)
if b == 0:
return a
return gcd(b, a % b)
t = int(input())
isp = [1] * 1010
p = []
for i in range(2, 1000):
if isp[i]:
p += [i]
for j in range(i + i, 1000, i):
isp[j] = 0
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
k = 0
c = [0] * n
for i in range(n):
if c[i] == 0:
k += 1
x = -1
for pp in p:
if a[i] % pp == 0:
x = pp
break
for j in range(i, n):
if a[j] % x == 0:
c[j] = k
print(k)
print(*c) | FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR 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 ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR 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. | import sys
inp = sys.stdin.readline
def input():
return inp().strip()
def iin():
return int(input())
def lin():
return list(map(int, input().split()))
def main():
T = iin()
while T:
T -= 1
n = iin()
a = [[j, i] for i, j in enumerate(lin())]
ans = []
for i in range(2, 1000):
if not a:
break
a1 = []
a2 = []
for j, k in a:
if j % i == 0:
a2.append(k)
else:
a1.append([j, k])
if a2:
ans.append(a2)
a = a1
print(len(ans))
a1 = [0] * n
for k, i in enumerate(ans):
for j in i:
a1[j] = k + 1
print(*a1)
main() | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR 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())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
prime = []
c = 0
res = [0] * n
col = {}
for i in range(n):
for j in range(2, int(pow(a[i], 0.5)) + 1):
if a[i] % j == 0:
if j not in prime:
prime.append(j)
c += 1
col[j] = c
res[i] = col[j]
break
else:
res[i] = col[j]
break
print(c)
for i in range(n):
print(res[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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR 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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
colors = [-1] * 10001
for i in range(len(primes)):
p = primes[i]
for j in range(0, 10001, p):
colors[j] = i
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
s = set({})
for i in a:
s.add(colors[i])
s = list(s)
mapping = {}
for i in range(len(s)):
mapping[s[i]] = i + 1
print(len(s))
for i in a:
print(mapping[colors[i]], end=" ") | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR 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. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = {}
cold = {}
vis = {}
col = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
for i in range(n):
if a[i] % 2 == 0:
if 2 in vis:
d[i] = vis[2]
else:
d[i] = col[0]
vis[2] = col[0]
col.pop(0)
elif a[i] % 3 == 0:
if 3 in vis:
d[i] = vis[3]
else:
d[i] = col[0]
vis[3] = col[0]
col.pop(0)
elif a[i] % 5 == 0:
if 5 in vis:
d[i] = vis[5]
else:
d[i] = col[0]
vis[5] = col[0]
col.pop(0)
elif a[i] % 7 == 0:
if 7 in vis:
d[i] = vis[7]
else:
d[i] = col[0]
vis[7] = col[0]
col.pop(0)
elif a[i] % 11 == 0:
if 11 in vis:
d[i] = vis[11]
else:
d[i] = col[0]
vis[11] = col[0]
col.pop(0)
elif a[i] % 13 == 0:
if 13 in vis:
d[i] = vis[13]
else:
d[i] = col[0]
vis[13] = col[0]
col.pop(0)
elif a[i] % 17 == 0:
if 17 in vis:
d[i] = vis[17]
else:
d[i] = col[0]
vis[17] = col[0]
col.pop(0)
elif a[i] % 19 == 0:
if 19 in vis:
d[i] = vis[19]
else:
d[i] = col[0]
vis[19] = col[0]
col.pop(0)
elif a[i] % 23 == 0:
if 23 in vis:
d[i] = vis[23]
else:
d[i] = col[0]
vis[23] = col[0]
col.pop(0)
elif a[i] % 29 == 0:
if 29 in vis:
d[i] = vis[29]
else:
d[i] = col[0]
vis[29] = col[0]
col.pop(0)
elif a[i] % 31 == 0:
if 31 in vis:
d[i] = vis[31]
else:
d[i] = col[0]
vis[31] = col[0]
col.pop(0)
maxi = max(d.values())
print(maxi)
for i in d.values():
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 DICT ASSIGN VAR DICT ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL 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. | n = int(input())
l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for k in range(n):
a = int(input())
t = list(map(int, input().split()))
ans = []
count = 0
l1 = [0]
for i in t:
check = False
for j in range(1, len(l1)):
if i % l1[j] == 0:
ans.append(j)
check = True
break
if check == False:
for j in l:
if i % j == 0:
count += 1
l1.append(j)
ans.append(count)
break
print(count)
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 LIST ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR 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. | pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in range(11):
for j in range(n):
if b[j] == 0 and a[j] % pr[i] == 0:
b[j] = i + 1
r = max(b)
for i in range(1, r + 1):
r = max(b)
while i not in b and i < r:
for j in range(n):
if b[j] > i:
b[j] -= 1
print(max(b))
print(*b) | 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR 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. | def answer(n, A):
dp = [1] * 32
dp[0] = dp[1] = 0
for i in range(2, 32):
if dp[i] == 1:
p = 2 * i
while p <= 31:
if dp[p] == 1:
dp[p] = 0
p += i
count = 1
res = [0] * n
for i in range(2, 32):
if dp[i] == 1:
flag = 0
for j in range(n):
if res[j] == 0 and A[j] % i == 0:
flag = 1
res[j] = count
if flag == 1:
count += 1
return count, res
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
a, b = answer(n, arr)
print(a - 1)
print(*b) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER 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 VAR FUNC_CALL 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. | def minprimefactor(x):
if x % 2 == 0:
return 2
for i in range(3, x + 1, 2):
if x % i == 0:
return i
def tough(n, a):
prime = []
res = []
v = 0
for i in range(n):
l = minprimefactor(a[i])
if l in prime:
res.append(prime.index(l) + 1)
else:
prime.append(l)
v += 1
res.append(v)
print(len(prime))
print(*res)
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
tough(n, a) | FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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. | def program():
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
used = []
n = int(input())
l = list(map(int, input().split()))
color = 1
dic = dict()
for x in l:
for p in prime:
if x % p == 0:
add = prime.index(p) + 1
used.append(add)
if add not in dic.keys():
dic[add] = color
color += 1
break
print(len(dic))
for x in used:
print(dic[x], end=" ")
print()
for i in range(int(input())):
program() | FUNC_DEF 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR 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
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, input().split())
def rlinput():
return list(map(int, input().split()))
def main():
def pro(a, b, x, x1, x2):
if (a == -2 * b or x != x1 or x != x2 or b == 0) and x1 <= x - a + b <= x2:
return True
return False
n = iinput()
q = rlinput()
w = dict()
for i in range(n):
for o in range(2, 1001):
if q[i] % o == 0:
if o in w:
w[o].append(i)
else:
w[o] = [i]
break
m = 1
res = [1] * n
for i in w:
for o in w[i]:
res[o] = m
m += 1
print(m - 1)
print(*res)
for i in range(iinput()):
main() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_DEF IF VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR 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. | dp = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for T in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
final = []
mx = 0
d = {}
for i in range(n):
for j in range(11):
if arr[i] % dp[j] == 0:
if d.get(j, 0):
final.append(d[j])
else:
d[j] = mx + 1
final.append(mx + 1)
mx += 1
break
print(mx)
print(*final) | 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 DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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. | import sys
def input():
return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
c = 1
color = {}
for i, el in enumerate(a):
for y in range(2, el + 1):
if el % y == 0:
if y not in color:
color[y] = c
c += 1
ans[i] = str(color[y])
break
print(c - 1)
print(" ".join(ans)) | IMPORT FUNC_DEF RETURN 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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. | t = int(input())
for i in range(t):
n, s, p, q, d, k = int(input()), input().split(), [0] * 11, [], dict(), 0
for i in range(n):
if int(s[i]) % 2 == 0:
q.append(1)
p[0] = 1
elif int(s[i]) % 3 == 0:
p[1] = 1
q.append(2)
elif int(s[i]) % 5 == 0:
p[2] = 1
q.append(3)
elif int(s[i]) % 7 == 0:
p[3] = 1
q.append(4)
elif int(s[i]) % 11 == 0:
p[4] = 1
q.append(5)
elif int(s[i]) % 13 == 0:
p[5] = 1
q.append(6)
elif int(s[i]) % 17 == 0:
p[6] = 1
q.append(7)
elif int(s[i]) % 19 == 0:
p[7] = 1
q.append(8)
elif int(s[i]) % 23 == 0:
p[8] = 1
q.append(9)
elif int(s[i]) % 29 == 0:
p[9] = 1
q.append(10)
elif int(s[i]) % 31 == 0:
p[10] = 1
q.append(11)
for i in range(11):
if p[i] == 1:
d[i + 1] = k + 1
k = k + 1
for i in range(n):
q[i] = d[q[i]]
print(k)
print(" ".join(str(i) for i in q)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER LIST FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR 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. | id = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31
for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
f = [0] * 32
res, t = [], 1
for x in a:
for i in id:
if x % i == 0:
if f[i] == 0:
f[i] = t
res.append(f[i])
t += 1
else:
res.append(f[i])
break
print(t - 1)
print(*res) | ASSIGN VAR 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL 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())
while t:
t -= 1
n = int(input())
a = [int(k) for k in input().split()]
divBy = [0] * 1001
divBy[1] = 1
for i in range(2, 1001):
if divBy[i] == 0:
for j in range(i, 1001, i):
if divBy[j] == 0:
divBy[j] = i
if n <= 11:
print(n)
print(*[i for i in range(1, n + 1)])
else:
divisor = {}
for i, num in enumerate(a):
if divBy[num] in divisor:
divisor[divBy[num]].append(i)
else:
divisor[divBy[num]] = [i]
ans = [0] * 1001
temp = 1
for templist in divisor.values():
for numIndex in templist:
ans[numIndex] = temp
temp += 1
print(temp - 1)
print(*ans[:n]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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. | from sys import stdin, stdout
def read():
x0 = stdin.readline().rstrip()
return x0
def __main__():
t = int(read())
for t0 in range(t):
n = int(read())
A = [int(i) for i in read().split()]
res = []
d = {}
ind = 0
for a in A:
if a % 2 == 0:
if 2 not in d:
ind += 1
d.update({(2): ind})
res.append(d.get(2))
elif a % 3 == 0:
if 3 not in d:
ind += 1
d.update({(3): ind})
res.append(d.get(3))
elif a % 5 == 0:
if 5 not in d:
ind += 1
d.update({(5): ind})
res.append(d.get(5))
elif a % 7 == 0:
if 7 not in d:
ind += 1
d.update({(7): ind})
res.append(d.get(7))
elif a % 11 == 0:
if 11 not in d:
ind += 1
d.update({(11): ind})
res.append(d.get(11))
elif a % 13 == 0:
if 13 not in d:
ind += 1
d.update({(13): ind})
res.append(d.get(13))
elif a % 17 == 0:
if 17 not in d:
ind += 1
d.update({(17): ind})
res.append(d.get(17))
elif a % 19 == 0:
if 19 not in d:
ind += 1
d.update({(19): ind})
res.append(d.get(19))
elif a % 23 == 0:
if 23 not in d:
ind += 1
d.update({(23): ind})
res.append(d.get(23))
elif a % 29 == 0:
if 29 not in d:
ind += 1
d.update({(29): ind})
res.append(d.get(29))
elif a % 31 == 0:
if 31 not in d:
ind += 1
d.update({(31): ind})
res.append(d.get(31))
r = [str(k) for k in res]
r0 = " ".join(r) + "\n"
nx = str(max(res)) + "\n"
stdout.write(nx)
stdout.write(r0)
__main__() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF 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 ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR 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. | def minpr(a):
for i in range(2, a):
if a % i == 0:
return i
t = int(input())
for _ in range(t):
l = int(input())
arr = list(map(int, input().split()))
count = 1
d = {}
for i in range(l):
arr[i] = minpr(arr[i])
if arr[i] not in d:
d[arr[i]] = count
count += 1
for i in range(l):
arr[i] = d[arr[i]]
print(max(arr))
print(*arr, sep=" ") | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR 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. | t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
y = 0
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 2 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 3 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 5 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 7 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 11 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 13 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 17 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 19 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 23 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 29 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
czy = True
for j in range(n):
if b[j] == 0 and a[j] % 31 == 0:
if czy:
y = y + 1
czy = False
b[j] = y
stri = ""
for j in range(n):
stri = stri + str(b[j]) + " "
print(y)
print(stri) | 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR STRING 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().strip()
ipnut = input
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(int(input())):
n = int(ipnut())
a = list(map(int, ipnut().split()))
ans = []
an = 1
color = {}
for i in a:
ansv = 0
for j in prime:
ansv += 1
if i % j == 0:
if ansv not in color:
color[ansv] = an
an += 1
break
ans.append(color[ansv])
print(an - 1)
print(*ans) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR 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 DICT FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR 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 |
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 find_ans(n, s):
ans = []
m = 1
q = dict()
for i in s:
for j in primes:
if i % j == 0:
if j in q:
ans.append(str(q[j]))
else:
ans.append(str(m))
q[j] = m
m += 1
break
print(m - 1)
print(" ".join(ans))
for _ in range(int(input())):
n = int(input())
s = list(map(int, input().split()))
find_ans(n, s) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING 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
input = sys.stdin.readline
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for ti in range(int(input().strip())):
n = int(input().strip())
a = [int(x) for x in input().strip().split()]
v = [0] * len(a)
ans = [0] * len(a)
cc = [0] * len(primes)
cn = 0
for pi in range(len(primes)):
for ai in range(len(a)):
if not v[ai] and a[ai] % primes[pi] == 0:
v[ai] = 1
if not cc[pi]:
cn += 1
cc[pi] = 1
ans[ai] = cn
print(cn)
print(*ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR 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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for i in range(t):
n = int(input())
ls = [int(a) for a in input().split()]
an = []
for j in range(n):
an.append(0)
ctr = 1
for p in range(len(primes)):
nx = False
for j in range(n):
if ls[j] % primes[p] == 0 and an[j] == 0:
an[j] = ctr
nx = True
if nx == True:
ctr += 1
s = ""
for a in an:
s += str(a) + " "
print(ctr - 1)
print(s) | 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER 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 NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING 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. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
mx = max(a)
div = {i: [] for i in range(2, mx + 1)}
vis = [0] * n
for j in range(n):
el = a[j]
i = 2
while i * i <= el:
if el % i == 0:
div[i].append(j)
if el // i != i:
div[el // i].append(j)
i += 1
m = 0
for i in range(2, mx + 1):
m += 1
flag = True
for el in div[i]:
if vis[el] == 0:
vis[el] = 1
a[el] = m
flag = False
if flag:
m -= 1
print(m)
for el in a:
print(el, 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 FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR 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. | p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for t in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
ac = [0] * n
pc = [0] * 11
for i in range(n):
for j in range(11):
if a[i] % p[j] == 0:
ac[i] = p[j]
pc[j] += 1
break
total = 0
for i in range(11):
if pc[i] > 0:
total += 1
for j in range(n):
if ac[j] == p[i]:
ac[j] = total
print(total)
print(*ac) | 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 BIN_OP LIST NUMBER VAR 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 ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR 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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
n = int(input())
for i in range(n):
r = int(input())
s = [int(x) for x in input().split()]
ans = []
yes = [(0) for i in range(11)]
for m in range(len(s)):
for j in range(11):
if s[m] % primes[j] == 0:
ans.append(j)
yes[j] = 1
break
yesthen = [(0) for k in range(11)]
yesthen[0] = yes[0]
for k in range(10):
yesthen[k + 1] = yes[k + 1] + yesthen[k]
print(yesthen[10])
for m in range(len(s)):
print(yesthen[ans[m]], end=" ")
print() | 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 LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL 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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL 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
input = stdin.readline
def A():
t = int(input())
for _ in range(t):
a, b, c, d = map(int, input().split())
x, y, x1, y1, x2, y2 = map(int, input().split())
netr = b - a
netu = d - c
if x1 == x2 and (a > 0 or b > 0):
print("No")
continue
if y1 == y2 and (c > 0 or d > 0):
print("No")
continue
if netr + x < x1 or netr + x > x2:
print("No")
continue
if netu + y < y1 or netu + y > y2:
print("No")
continue
print("Yes")
def B():
t = int(input())
for _ in range(t):
m = int(input())
a = list(map(int, input().split()))
c = [0] * m
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
used = [False] * 11
for i in range(m):
j = 0
while a[i] % p[j] != 0:
j += 1
used[j] = True
c[i] = j
used[0] = int(used[0])
for i in range(1, 11):
used[i] = int(used[i]) + used[i - 1]
for i in range(m):
c[i] = used[c[i]]
print(max(used))
print(*c)
B() | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF 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 BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR 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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
while t:
t -= 1
n = int(input())
res = []
tracker = [(False) for x in range(11)]
nums = list(int(x) for x in input().split())
for num in nums:
for i, p in enumerate(primes):
if num % p == 0:
tracker[i] = True
break
count = 0
tracker2 = [(-1) for x in range(11)]
for i in range(11):
if tracker[i]:
count += 1
tracker2[i] = count
for num in nums:
for i, p in enumerate(primes):
if num % p == 0:
res.append(tracker2[i])
break
print(count)
for x in res:
print(x, " ", end="") | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING 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(arr):
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
res = []
for i in arr:
for p in primes:
if i % p == 0:
res.append(p)
break
d = {}
index = 1
for i in range(len(res)):
if res[i] not in d:
d[res[i]] = index
index += 1
res[i] = d[res[i]]
print(index - 1)
print(" ".join(map(str, res)))
T = int(input())
for ti in range(1, T + 1):
N = int(input())
arr = list(map(int, input().split(" ")))
solve(arr) | FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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. | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split(" ")))
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
p_associated = []
dic = {}
for i in a:
for p in primes:
if i % p == 0:
p_associated.append(p)
if p not in dic.keys():
dic[p] = [i]
else:
dic[p].append(i)
break
print(len(dic.keys()))
color = {}
c = 1
for p in dic.keys():
color[p] = c
c += 1
for i in p_associated:
print(color[i], end=" ") | 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 LIST ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR 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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def f():
n = int(input())
A = [int(s) for s in input().split()]
tags = {p: (0) for p in primes}
tg = 0
for i in range(n):
for p in primes:
if not A[i] % p:
if not tags[p]:
tg += 1
tags[p] = tg
A[i] = tags[p]
break
print(tg)
print(" ".join(str(a) for a in A))
for t in range(int(input())):
f() | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR 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 hdsajgbiejka in range(t):
n = int(input())
a = list(map(int, input().split()))
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
b = []
for i in a:
for j in primes:
if i % j == 0:
b.append(j)
break
a = dict()
cc = 1
for i in b:
try:
a[i] = a[i]
except KeyError:
a[i] = cc
cc += 1
print(cc - 1)
print(*[a[i] for i in b]) | 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 VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR 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. | debug = 0
if debug:
print("DEBUG MODE ON")
f = None
def new_input():
global f
if f == None:
f = open("input.txt")
return f.readline()
input = new_input
def readrange():
return range(int(input()))
def readint():
return int(input())
def readarr():
return [int(x) for x in input().split()]
def readmat(rows):
return [readarr() for _ in range(rows)]
primes = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31
for _ in readrange():
input()
arr = readarr()
for k in range(len(arr)):
arr[k] = min(p for p in primes if arr[k] % p == 0)
colors = tuple(set(arr))
print(len(colors))
print(*[(colors.index(element) + 1) for element in arr]) | ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NONE FUNC_DEF IF VAR NONE ASSIGN VAR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL 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. | d = {}
primel = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(4, 1001):
for j in primel:
if i % j == 0:
d[i] = j
break
for t in range(int(input())):
n = int(input())
l = [d[i] for i in map(int, input().split())]
s = list(set(l))
print(len(s))
print(*[(s.index(i) + 1) for i in l]) | ASSIGN VAR DICT ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR 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 VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL 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. | import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
n = int(input())
A = [int(i) for i in input().split()]
D = []
for a in A:
for p in P:
if a % p == 0:
D.append(p)
break
print(len(set(D)))
DD = list(set(D))
DDD = dict()
cl = 1
for dd in DD:
DDD[dd] = cl
cl += 1
Ans = []
for d in D:
Ans.append(DDD[d])
print(*Ans) | IMPORT ASSIGN 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 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 FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR 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. | spf = [0] * 1001
def sieve():
spf[1] = 1
for i in range(2, 1001):
spf[i] = i
for i in range(4, 1001, 2):
spf[i] = 2
i = 3
while i * i < 1001:
if spf[i] == i:
for j in range(i * i, 1001, i):
if spf[j] == j:
spf[j] = i
i = i + 1
sieve()
t = int(input())
while t > 0:
t = t - 1
n = int(input())
a = input()
A = list(map(int, list(a.split())))
vis = [0] * n
ta = [0] * n
for i in range(n):
ta[i] = spf[A[i]]
c = 0
for i in range(n):
if vis[i] == 0:
c = c + 1
vis[i] = c
for j in range(i + 1, n):
if spf[A[j]] == spf[A[i]]:
vis[j] = c
d = {}
e = 0
for i in range(n):
if vis[i] not in d:
d[vis[i]] = 1
e = e + 1
print(e)
for i in vis:
print(i, end=" ")
print() | ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR 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. | d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
answer = []
for i in range(n):
for j in range(11):
if a[i] % d[j] == 0:
answer.append(j + 1)
break
st = list(set(answer))
st.sort()
print(len(st))
for i in range(n):
print(st.index(answer[i]) + 1, end=" ")
print() | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR 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. | for i in range(int(input())):
n = int(input())
num = list(map(int, input().split()))
m = 0
color = 32 * [0]
for j in range(n):
for k in range(2, 32):
if num[j] % k == 0:
if color[k]:
break
else:
m += 1
color[k] = m
break
print(m)
for j in range(n):
for k in range(2, 32):
if num[j] % k == 0:
print(color[k], end=" ")
break
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 NUMBER ASSIGN VAR BIN_OP NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER 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. | t = int(input())
for rep in range(t):
n = int(input())
a = list(map(int, input().split()))
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
colarr = [0] * n
m = 0
for i in range(11):
f = 0
for j in range(n):
if a[j] % primes[i] == 0 and colarr[j] == 0:
colarr[j] = m + 1
f = 1
if f == 1:
m += 1
print(m)
print(" ".join(list(map(str, colarr)))) | 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 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 VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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. | cases = int(input())
for case in range(cases):
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
primes_used = []
numbers = int(input())
sequence = list(map(int, input().split(" ")))
result = [0] * len(sequence)
colors_used = 0
for i in range(len(sequence)):
for p in range(len(primes)):
if sequence[i] % primes[p] == 0:
if primes[p] in primes_used:
result[i] = primes_used.index(primes[p]) + 1
else:
primes_used.append(primes[p])
colors_used += 1
result[i] = colors_used
break
string_result = [str(num) for num in result]
print(colors_used)
print(" ".join(string_result)) | 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR 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 IF VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR 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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in [0] * int(input()):
n = int(input())
(*A,) = map(int, input().split())
factor = [0] * n
k = 0
used = [False] * 32
factor_to_c = {}
for i, a in enumerate(A):
for p in primes:
if a % p == 0:
if not used[p]:
used[p] = True
k += 1
factor_to_c[p] = k
factor[i] = p
break
print(k)
print(*[factor_to_c[p] for p in factor]) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR 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. | for _ in range(int(input())):
n = int(input())
a = [0] * int(1000**0.5 + 1)
m = 0
ans = []
c = list(map(int, input().split()))
for i in range(n):
b = c[i]
for i in range(2, int(b**0.5) + 1):
if b % i == 0:
if a[i] == 0:
m += 1
a[i] = m
ans.append(a[i])
break
print(m)
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER 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. | p = set()
for i in range(2, 1001):
ok = True
for j in range(2, int(i**0.5) + 1):
if i % j == 0:
ok = False
break
if ok:
p.add(i)
first11Primes = sorted(list(p))[:11]
getColour = [(-1) for _ in range(1001)]
for i in range(4, 1001):
for j in range(len(first11Primes)):
if i % first11Primes[j] == 0:
getColour[i] = j
break
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
usedColours = set()
for x in a:
usedColours.add(getColour[x])
usedColours = sorted(list(usedColours))
mapp = dict()
j = 1
for co in usedColours:
mapp[co] = j
j += 1
ans = [(-1) for __ in range(n)]
for i in range(n):
ans[i] = mapp[getColour[a[i]]]
print(j - 1)
print(" ".join([str(x) for x in ans])) | ASSIGN VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR 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. | def primes(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
primes = primes(int(1000**0.5) + 1)
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
ret = [0] * n
idx = 1
for j in range(11):
max_index = 0
max_count = 0
for k in range(len(primes)):
count = sum(1 for i in range(n) if a[i] % primes[k] == 0 and ret[i] == 0)
if count > max_count:
max_index = k
max_count = count
if max_count == 0:
break
for i in range(n):
if a[i] % primes[max_index] == 0 and ret[i] == 0:
ret[i] = idx
idx += 1
print(idx - 1)
print(*ret) | 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 FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP 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 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER 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. | def solve(ans1, ans2):
n = int(input())
li = [int(x) for x in input().split()]
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
d = {}
clr = []
colour = 1
for ele in li:
for i in range(11):
if ele % primes[i] == 0:
if primes[i] not in d:
d[primes[i]] = colour
colour += 1
clr.append(d[primes[i]])
break
ans1.append(colour - 1)
ans2.append(clr)
return
n = int(input())
ans1 = []
ans2 = []
for i in range(n):
solve(ans1, ans2)
for i in range(n):
print(ans1[i])
print(*ans2[i]) | FUNC_DEF 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 DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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. | for _ in range(int(input())):
dic = {
(2): 0,
(3): 0,
(5): 0,
(7): 0,
(11): 0,
(13): 0,
(17): 0,
(19): 0,
(23): 0,
(29): 0,
(31): 0,
}
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
n = int(input())
lst = list(map(int, input().split()))
temp = []
col = 0
for i in range(n):
for a in range(11):
if lst[i] % prime[a] == 0:
if dic[prime[a]] == 0:
col += 1
dic[prime[a]] = col
temp.append(dic[prime[a]])
break
print(col)
print(*temp) | FOR VAR FUNC_CALL 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 LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 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 NUMBER 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. | import sys
input = sys.stdin.readline
t = int(input())
ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
def compress(init_val):
t = sorted(set(init_val))
d = dict([[t[i], i] for i in range(len(t))])
res = [0] * len(init_val)
for i in range(len(init_val)):
res[i] = d[init_val[i]]
return res
for _ in range(t):
N = int(input())
a = list(map(int, input().split()))
res = [0] * N
for i in range(N):
for j in range(11):
if a[i] % ps[j] == 0:
res[i] = j + 1
break
res = compress(res)
for i in range(N):
res[i] += 1
print(max(res))
print(*res) | 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN 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 VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL 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. | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
narr = [(0) for _ in range(n)]
for i, x in enumerate(arr):
for j, p in enumerate(primes):
if not x % p:
narr[i] = j + 1
break
snr = set(narr)
dct = {}
i = 1
for s in snr:
dct[s] = i
i += 1
print(len(snr))
print(*map(lambda x: dct[x], narr)) | 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 NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT 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 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. | L2 = [
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,
]
L3 = [
101,
103,
107,
109,
113,
127,
131,
137,
139,
149,
151,
157,
163,
167,
173,
179,
181,
191,
193,
197,
199,
]
L4 = [211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293]
L5 = [307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397]
L6 = [
401,
409,
419,
421,
431,
433,
439,
443,
449,
457,
461,
463,
467,
479,
487,
491,
499,
]
L7 = [
503,
509,
521,
523,
541,
547,
557,
563,
569,
571,
577,
587,
593,
599,
601,
607,
613,
617,
619,
631,
641,
643,
647,
653,
659,
661,
673,
677,
683,
691,
]
L8 = [
701,
709,
719,
727,
733,
739,
743,
751,
757,
761,
769,
773,
787,
797,
809,
811,
821,
823,
827,
829,
839,
853,
857,
859,
863,
877,
881,
883,
887,
]
L9 = [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
L2 = L2 + L3 + L4 + L5 + L6 + L7 + L7 + L9
t = int(input())
for i in range(t):
n = int(input())
ch = input()
k = 1
L = [int(i) for i in ch.split()]
d = dict()
for i in range(len(L2)):
d[L2[i]] = -1
L3 = [0] * n
for w in range(n):
for j in range(25):
if L[w] % L2[j] == 0:
if d[L2[j]] == -1:
d[L2[j]] = k
k += 1
L3[w] = d[L2[j]]
break
s = ""
for w in range(n):
s += str(L3[w]) + " "
print(max(L3))
print(s) | 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 ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 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 ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR 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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER 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 IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR 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 |
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
def main():
t = int(stdin.readline())
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
color_count = 0
used = [0] * 11
mp = {}
res = []
for x in arr:
for i, div in enumerate(prime):
if x % div == 0:
if used[i] == 0:
color_count += 1
used[i] = 1
mp[div] = color_count
res.append(mp[div])
break
else:
res.append(mp[div])
break
stdout.write(str(color_count) + "\n")
stdout.write(" ".join([str(x) for x in res]) + "\n")
main() | FUNC_DEF 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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING 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. | t = int(input())
while t:
t += -1
n = int(input())
l = list(map(int, input().split()))
x = 1
col = [0] * 1005
for i in range(2, 1002):
if col[i]:
continue
for j in range(2, 1005):
if j % i == 0:
if col[j] == 0:
col[j] = x
x -= -1
temp = []
for i in l:
temp.append(col[i])
temp = list(set(temp))
dic = {}
x = 1
for i in temp:
dic[i] = x
x -= -1
print(len(set(temp)))
for i in l:
print(dic[col[i]], end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR 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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR 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. | t = int(input())
i = 0
while i < t:
n = int(input())
arr = list(map(int, input().split()))
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
temp = {
(2): 36,
(3): 36,
(5): 36,
(7): 36,
(11): 36,
(13): 36,
(17): 36,
(19): 36,
(23): 36,
(29): 36,
(31): 36,
}
count = 1
ans = []
for x in arr:
for y in prime:
if x % y == 0:
if temp[y] == 36:
temp[y] = count
count = count + 1
ans.append(temp[y])
break
print(count - 1)
print(*ans, sep=" ")
i = i + 1
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE 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 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 ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 i10 in range(t):
k = 0
s = 0
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
f = [0] * 11
g = [0] * 11
for i in range(n):
if a[i] % 2 == 0:
if f[0] == 1:
b[i] = g[0]
else:
s += 1
b[i] = s
g[0] = s
f[0] = 1
elif a[i] % 3 == 0:
if f[1] == 1:
b[i] = g[1]
else:
s += 1
b[i] = s
g[1] = s
f[1] = 1
elif a[i] % 5 == 0:
if f[2] == 1:
b[i] = g[2]
else:
s += 1
b[i] = s
g[2] = s
f[2] = 1
elif a[i] % 7 == 0:
if f[3] == 1:
b[i] = g[3]
else:
s += 1
b[i] = s
g[3] = s
f[3] = 1
elif a[i] % 11 == 0:
if f[4] == 1:
b[i] = g[4]
else:
s += 1
b[i] = s
g[4] = s
f[4] = 1
elif a[i] % 13 == 0:
if f[5] == 1:
b[i] = g[5]
else:
s += 1
b[i] = s
g[5] = s
f[5] = 1
elif a[i] % 17 == 0:
if f[6] == 1:
b[i] = g[6]
else:
s += 1
b[i] = s
g[6] = s
f[6] = 1
elif a[i] % 19 == 0:
if f[7] == 1:
b[i] = g[7]
else:
s += 1
b[i] = s
g[7] = s
f[7] = 1
elif a[i] % 23 == 0:
if f[8] == 1:
b[i] = g[8]
else:
s += 1
b[i] = s
g[8] = s
f[8] = 1
elif a[i] % 29 == 0:
if f[9] == 1:
b[i] = g[9]
else:
s += 1
b[i] = s
g[9] = s
f[9] = 1
elif a[i] % 31 == 0:
if f[10] == 1:
b[i] = g[10]
else:
s += 1
b[i] = s
g[10] = s
f[10] = 1
print(max(b))
print(*b) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER 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 find_colour(n):
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(n):
if n % primes[i] == 0:
return i + 1
return False
def solve():
n = int(input())
numbers = [int(x) for x in input().split()]
answers = []
colours = set()
for i in numbers:
c = find_colour(i)
colours.add(c)
answers.append(c)
colours = list(colours)
k = len(colours)
transpose = dict()
for i in range(k):
transpose[colours[i]] = i + 1
for i in range(n):
answers[i] = transpose[answers[i]]
return answers + [k]
t = int(input())
for case in range(t):
answer = solve()
print(answer.pop())
print(*answer) | FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN BIN_OP VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR 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. | p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
I = lambda: list(map(int, input().split()))
for tc in range(int(input())):
(n,) = I()
l = I()
c = [0] * n
for i in range(n):
for j in range(11):
if l[i] % p[j] == 0:
c[i] = j + 1
print(len(set(c)))
cn = 1
f = {}
for i in set(c):
f[i] = cn
cn += 1
anss = [f[i] for i in c]
print(*anss) | ASSIGN VAR LIST 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 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 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 NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER 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())
pl = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
n = int(input())
l = [int(i) for i in input().strip().split(" ")]
o = []
for i in l:
for p in pl:
if i % p == 0:
o.append(p)
break
op = list(set(o))
m = len(op)
of = []
for i in o:
of.append(op.index(i) + 1)
print(m)
print(*of) | 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 VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL 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. | t = int(input())
for case in range(t):
n = int(input())
A = [int(x) for x in input().split()]
used = [0] * 11
counter = 0
for i in range(len(A)):
for x, p in enumerate([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]):
if A[i] % p == 0:
if used[x] == 0:
counter += 1
used[x] = counter
A[i] = used[x]
break
print(counter)
print(" ".join([str(y) for y in 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR 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. | def func():
n = int(input())
arr = [int(x) for x in input().split()]
primes = [
[2, False],
[3, False],
[5, False],
[7, False],
[11, False],
[13, False],
[17, False],
[19, False],
[23, False],
[29, False],
[31, False],
]
k = 0
ans = []
for i in arr:
for j in range(len(primes)):
if i % primes[j][0] == 0:
if primes[j][1] == False:
primes[j][1] = True
k += 1
primes[j].append(k)
ans.append(primes[j][2])
else:
ans.append(primes[j][2])
break
print(k)
[print("%d" % x, end=" ") for x in ans]
print("")
t = int(input())
while t != 0:
t -= 1
func() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER 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. | Numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
Check = [0] * 11
N = int(input())
Color = 1
X = list(map(int, input().split()))
Answer = []
for i in X:
Index = 0
for j in range(11):
if i % Numbers[j] == 0:
Index = j
break
if Check[Index] != 0:
Answer.append(Check[Index])
else:
Answer.append(Color)
Check[Index] = Color
Color += 1
print(max(Answer))
print(*Answer) | 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN 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. | T = int(input())
for _ in range(T):
n = int(input())
A = list(map(int, input().split()))
R = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
C = [(0) for i in range(32)]
D = [(0) for i in range(n)]
m = 1
for i in range(n):
for j in range(11):
if A[i] % R[j] == 0:
if C[R[j]] == 0:
D[i] = m
C[R[j]] = m
m = m + 1
else:
D[i] = C[R[j]]
break
print(m - 1)
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 LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR 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 NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP 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())
cases = []
for _ in range(t):
n = int(input())
a = [int(i) for i in input().split()]
cases.append(a)
p = [None for _ in range(1001)]
for i in range(2, 1001):
for j in range(2, 1001):
if i % j == 0:
p[i] = j
break
for c in cases:
colors = 0
s = {}
ans = [None for _ in range(len(c))]
for i, el in enumerate(c):
d = p[el]
if s.get(d) is None:
colors += 1
s[d] = colors
ans[i] = s[d]
print(colors)
print(" ".join([str(i) for i in ans])) | 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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NONE VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR 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. | t = int(input())
for _ in range(t):
n = int(input())
items = list(map(int, input().split()))
d = {}
i = 0
for item in items:
for j in range(2, 1001):
if item % j == 0:
if j not in d:
d[j] = [i]
else:
d[j] += [i]
break
i += 1
print(len(d))
res = [0] * n
i = 1
for item in list(d.values()):
for index in item:
res[index] = i
i += 1
for item in res:
print(item, 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 DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER 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. | for _ in range(int(input())):
n = int(input())
s = list(map(int, input().split()))
ans = []
nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
am = set()
check = []
for i in s:
for j in range(len(nums)):
if i % nums[j] == 0:
if j + 1 not in check:
check.append(j + 1)
ans.append(len(check))
else:
ans.append(check.index(j + 1) + 1)
am.add(j + 1)
break
print(len(am))
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 NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL 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. | t = int(input())
for j in range(t):
n = int(input())
vec = list(map(int, input().split()))
vec2 = []
prim = set()
for i in vec:
if i % 2 == 0:
vec2.append(2)
prim.add(2)
elif i % 3 == 0:
vec2.append(3)
prim.add(3)
elif i % 5 == 0:
vec2.append(5)
prim.add(5)
elif i % 7 == 0:
vec2.append(7)
prim.add(7)
elif i % 11 == 0:
vec2.append(11)
prim.add(11)
elif i % 13 == 0:
vec2.append(13)
prim.add(13)
elif i % 17 == 0:
vec2.append(17)
prim.add(17)
elif i % 19 == 0:
vec2.append(19)
prim.add(19)
elif i % 23 == 0:
vec2.append(23)
prim.add(23)
elif i % 29 == 0:
vec2.append(29)
prim.add(29)
elif i % 31 == 0:
vec2.append(31)
prim.add(31)
m = len(prim)
print(m)
dicti = {}
for i in vec2[: n - 1]:
if i not in dicti:
print(m, end=" ")
dicti[i] = m
m = m - 1
else:
print(dicti[i], end=" ")
if vec2[-1] not in dicti:
print(m)
dicti[i] = m
m = m - 1
else:
print(dicti[vec2[-1]]) | 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 FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN 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())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for kk in range(T):
n = int(input())
a = list(map(int, input().split()))
c = [0] * 10002
ans = 0
for i in range(11):
col = False
for j in a:
if c[j] == 0 and j % p[i] == 0:
c[j] = ans + 1
col = True
if col:
ans = ans + 1
print(ans)
j = 0
for i in a:
j = j + 1
if j == n:
print(c[i])
else:
print(c[i], end=" ") | 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR 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())
for i in range(t):
n = int(input())
mass = [int(x) for x in input().split()]
answer = [0] * n
ch = 1
count = n
for j in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
f = False
for o in range(n):
if mass[o] % j == 0 and not answer[o]:
answer[o] = ch
f = True
count -= 1
if f:
ch += 1
if count == 0:
break
print(ch - 1)
print(*answer) | 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 NUMBER ASSIGN VAR VAR FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER 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. | def solve(L):
sol = [0] * len(L)
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(len(L)):
for j in range(11):
if L[i] % p[j] == 0:
sol[i] = j + 1
break
return sol
for i in " " * int(input()):
n = int(input())
L = list(map(int, input().split()))
sol = solve(L)
count = [0] * 11
for i in sol:
count[i - 1] += 1
newc = []
for i in range(11):
if count[i]:
newc.append(i + 1)
d = dict()
for i in range(len(newc)):
d[newc[i]] = i + 1
for i in range(n):
sol[i] = d[sol[i]]
print(max(sol))
for i in sol:
print(i, end=" ")
print() | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL 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 RETURN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR 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. | R = lambda: map(int, input().split())
t = int(input())
def sieve(n):
a = [0] * (n + 1)
color = 1
for i in range(2, n + 1):
if a[i] == 0:
k = 2 * i
while k <= n:
if a[k] == 0:
a[k] = color
k += i
color += 1
return a
s = sieve(1000)
def calculate_rank(vector):
a = {}
rank = 1
for num in sorted(vector):
if num not in a:
a[num] = rank
rank = rank + 1
return [a[i] for i in vector]
for _ in range(t):
n = int(input())
a = list(R())
z = [s[x] for x in a]
z = calculate_rank(z)
print(max(z))
print(*z) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN 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 ASSIGN VAR VAR VAR VAR VAR ASSIGN 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 range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
if n <= 11:
color = list(set(range(1, n + 1)))
print(n)
print(*color)
else:
d = {}
output = []
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in arr:
for j in prime:
if i % j == 0:
if j not in d:
d[j] = len(d) + 1
output.append(d[j])
break
print(len(d))
print(*output) | 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 IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT 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 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. | def is_pr(k):
i = 2
while i < int(k**0.5) + 1:
if k % i == 0:
return False
i += 1
return True
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
ras = [(0) for k in range(n)]
now_kol = 1
for p in range(2, 32):
bol = False
for j in range(n):
if ras[j] == 0 and a[j] % p == 0:
ras[j] = now_kol
bol = True
if bol:
now_kol += 1
print(now_kol - 1)
print(" ".join(map(str, ras))) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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
input = sys.stdin.readline
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for tests in range(t):
n = int(input())
A = list(map(int, input().split()))
ANS = []
for a in A:
for i in range(11):
if a % P[i] == 0:
ANS.append(i + 1)
break
compression_dict = {a: (ind + 1) for ind, a in enumerate(sorted(set(ANS)))}
ANS = [compression_dict[a] for a in ANS]
print(max(ANS))
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 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 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 VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | m = int(input())
l = list(map(int, input().split()))
t = 0
print(sum(l[i] - l[i + 1] for i in range(m - 1) if l[i] > l[i + 1])) | 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 EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | n = int(input())
lst = list(map(int, input().split()))
sum1 = 0
for i in range(1, n):
sum1 += max(lst[i - 1] - lst[i], 0)
print(sum1) | 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 FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(1, n):
if d[i - 1] - d[i] > 0:
ans += d[i - 1] - d[i]
print(ans) | 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 FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | import sys
n = int(input())
a = [int(i) for i in input().split()]
i = n - 1
sum = 0
while i > 0:
if a[i] < a[i - 1]:
sum += a[i - 1] - a[i]
i -= 1
print(sum) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | def main():
input()
l = list(map(int, input().split()))
a = x = 0
for b in l:
if a > b:
x += a - b
a = b
print(x)
main() | FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | n = int(input())
l = list(map(int, input().split()))
cnt = 0
ans = 0
for i in range(1, n):
if l[i] + cnt < l[i - 1]:
ans += abs(l[i] + cnt - l[i - 1])
cnt += ans
l[i] += cnt
print(ans) | 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | input()
nums = [int(x) for x in input().split()]
ans = 0
for i in range(1, len(nums)):
if nums[i - 1] > nums[i]:
ans += nums[i - 1] - nums[i]
print(ans) | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
n = iinput()
a = get_list()
moves = 0
for i in range(1, n):
if a[i - 1] > a[i]:
moves += a[i - 1] - a[i]
print(moves) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | while True:
try:
def soln(n, a):
ans = 0
for i in range(1, n, 1):
ans += max(0, a[i - 1] - a[i])
print(ans)
def read():
n = int(input())
a = list(map(int, input().split()))
soln(n, a)
if __name__ == "__main__":
read()
except EOFError:
break | WHILE NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | n = int(input())
arr = [int(x) for x in input().split()]
if n == 1:
print(0)
else:
ans = 0
for i in range(1, n):
if arr[i] < arr[i - 1]:
ans += arr[i - 1] - arr[i]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | n = int(input())
A = list(map(int, input().split()))
prev_elem = -1
move_to_prop = 0
total_moves = 0
for i in range(len(A)):
if A[i] >= prev_elem:
prev_elem = A[i]
move_to_prop = 0
else:
move_to_prop += prev_elem - A[i]
total_moves += prev_elem - A[i]
prev_elem = A[i]
print(total_moves) | 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | n = int(input())
l = list(map(int, input().split()))
ans = 0
f = 0
ma = l[0]
for i in range(1, n):
if l[i] < l[i - 1]:
f = 1
else:
if f:
ans += ma - l[i - 1]
f = 0
ma = l[i]
if f:
ans += ma - l[-1]
print(ans) | 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 NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 β€ l β€ r β€ n) and increase ai by 1 for all i such that l β€ i β€ r.
Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 β€ i < n) ai β€ ai + 1 holds.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of array a. The next line contains n integers, separated by single spaces β array a (1 β€ ai β€ 109). The array elements are listed in the line in the order of their index's increasing.
Output
In a single line print a single integer β the answer to the problem.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 3
Output
0
Input
3
3 2 1
Output
2
Input
4
7 4 1 47
Output
6
Note
In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47]. | n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n - 1):
if a[i] <= a[i + 1] + s:
a[i + 1] = a[i + 1] + s
pass
else:
s += a[i] - (a[i + 1] + s)
a[i + 1] = a[i + 1] + s
print(s) | 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.