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.
y = int(input()) ans = [] p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] c = [0] * len(p) for i in range(y): n = int(input()) al = input().split() m = list(map(int, al)) c = [0] * n for j in range(n): q = m[j] for t in range(len(p)): if q % p[t] == 0: c[j] = t + 1 continue sc = set(c) sd = set(range(1, len(sc) + 1)) if sc == sd: ans.append(c) else: ext = list(sc - sd) toc = list(sd - sc) for j in range(n): if c[j] in ext: ind = ext.index(c[j]) c[j] = toc[ind] ans.append(c) for i in ans: print(len(set(i))) for j in i: print(j, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR 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.
primes = [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())) colors = [(0) for _ in range(n)] for i in range(n): for prime in primes: if a[i] % prime == 0: colors[i] = prime counter = 0 color_to_counter = {} for i in range(n): if colors[i] in color_to_counter: colors[i] = color_to_counter[colors[i]] else: counter += 1 color_to_counter[colors[i]] = counter colors[i] = counter print(counter) print(" ".join([str(item) for item in colors]))
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 NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN 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.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) colors = {} color = 1 ans = [] for num in arr: d = None for j in range(2, num): if num % j == 0: d = j break if d not in colors: colors[d] = color color += 1 ans.append(colors[d]) print(max(ans)) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR 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.
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(0, int(input())): n = int(input()) l = list(map(int, input().split())) ans = [] currno = 1 d = {} mt = 0 for i in l: for k in range(0, 11): j = p[k] if i % j == 0: if d.get(j, -1) == -1: d[j] = currno ans.append(currno) currno += 1 else: ans.append(d[j]) break m = len(d.keys()) print(m) s = "" for i in ans: s += str(i) + " " s.strip() print(s)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR 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.
class P1332B: def solve(self, a): primes = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 m = 1 color = [(-1) for _ in range(len(a))] for p in primes: update = False for i, ai in enumerate(a): if color[i] == -1 and ai % p == 0: color[i] = m update = True if update: m += 1 m -= 1 return m, color t = int(input()) for _ in range(t): n = int(input()) a = tuple(map(int, input().split())) sol = P1332B().solve(a) print(sol[0]) s = "" for c in sol[1]: s += str(c) + " " print(s)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR 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 FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] def gp(x): for i in range(2, x): if x % i == 0: return i return -1 for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) D = [(0) for i in range(11)] for i in range(n): x = P.index(gp(A[i])) D[x] = 1 c = 0 num = [] for i in range(11): num.append(c) if D[i]: c += 1 print(c) for i in range(n): x = P.index(gp(A[i])) print(num[x] + 1, end=" ") print()
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
import sys input = sys.stdin.readline LI = lambda: list(map(int, input().strip("\n").split())) MI = lambda: map(int, input().strip("\n").split()) SI = lambda: input().strip("\n") II = lambda: int(input().strip("\n")) for _ in range(II()): n = II() a = LI() clr = {} primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] ans = 1 for p in primes: cur = False for v in a: if v % p == 0 and not clr.get(v, False): clr[v] = ans cur = True if cur: ans += 1 print(ans - 1) for v in a: print(clr[v], end=" ") print()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) start = 2 end = 999 primes = [] for val in range(start, end + 1): if val > 1: for n in range(2, val): if val % n == 0: break else: primes.append(val) for pp in range(0, t): n = int(input()) ip = list(map(int, input().split())) visited = [(0) for i in range(0, n)] mydict = {} count = 0 f = 0 for p in primes: for i in range(0, n): if visited[i] == 0 and ip[i] % p == 0: count = count + 1 visited[i] = 1 if p not in mydict: mydict[p] = [i] else: mydict[p].append(i) if count >= n: f = 1 break if f == 1: break colour = [(0) for i in range(0, n)] col = 1 for i in mydict.keys(): arr = mydict[i] for index in arr: colour[index] = col col = col + 1 print(col - 1) for i in range(0, n - 1): print(colour[i], end=" ") print(colour[n - 1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR 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.
import sys def set_debug(debug_mode=False): if debug_mode: fin = open("input.txt", "r") fout = open("output.txt", "w") sys.stdin = fin sys.stdout = fout set_debug(False) p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for i in range(int(input())): input() a = [ min((i + 1 for i in range(11) if a % p[i] == 0), default=10**4) for a in map(int, input().split()) ] sa = sorted(set(a)) print(len(sa)) print(*[(sa.index(x) + 1) for x in a])
IMPORT FUNC_DEF NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER NUMBER 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.
t = int(input()) primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31} for _ in range(t): n = int(input()) arr = [int(x) for x in input().split()] colors = [(0) for x in range(n)] for p in primes: for ind, item in enumerate(arr): if not colors[ind] and item % p == 0: colors[ind] = p clrs = list(set(colors)) print(len(clrs)) for item in colors: print(clrs.index(item) + 1, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL 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.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] n = int(input()) for a in range(n): usedColors = 0 colorKey = {} length = int(input()) nums = list(map(int, input().split())) answer = "" for b in nums: for c in range(len(primes)): if b % primes[c] == 0: if c not in colorKey: usedColors += 1 colorKey[c] = usedColors answer += str(colorKey[c]) + " " break print(usedColors) print(answer)
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 NUMBER 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 STRING FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP 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.
t = int(input()) p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(t): n = int(input()) x = list(map(int, input().split())) ans, used, num = [0] * 1002, [0] * 12, [0] * 12 v = [] for i in x: for i2 in range(11): if i % p[i2] == 0: ans[i] = i2 + 1 used[i2 + 1] = 1 break count = 1 for i in range(1, 12): if used[i] == 1: num[i] = count count += 1 print(count - 1) for i in x: print(num[ans[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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR 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.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) c = [] d = {} ans = "" t = max(a) count = 0 for i in range(n): for j in range(2, t + 1): if a[i] % j == 0: if j in d: ans += str(d[j]) + " " else: count += 1 d[j] = count ans += str(count) + " " break print(count) 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 DICT ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL 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.
for ttt in range(int(input())): n = int(input()) arr = list(map(int, input().split())) res = [0] * n count = 1 prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for i in range(len(prime)): ok = 0 for j in range(n): if arr[j] % prime[i] == 0: if res[j] == 0: res[j] = count ok = 1 if ok: count += 1 print(count - 1) print(*res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = [0] * n track = 1 for p in primes: flag = 0 for i in range(n): if a[i] % p == 0: if b[i] == 0: b[i] = track flag = 1 if flag: track += 1 print(len(list(set(b)))) print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
I = input for _ in [0] * int(I()): I() a = [ next(p for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31) if int(x) % p < 1) for x in I().split() ] b = [*{*a}] print(len(b), *(b.index(x) + 1 for x in a))
ASSIGN VAR VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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.
t = int(input()) primes = "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31".split(", ") primes = list(map(int, primes)) while t: t -= 1 n = int(input()) arr = list(map(int, input().split())) asig = {} ans = [(0) for _ in range(n)] col = 0 for i, num in enumerate(arr): for p in primes: if num % p == 0: if p not in asig: col += 1 asig[p] = col ans[i] = asig[p] break print(col) print(" ".join(map(str, ans)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER 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
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(x, y): while y: x, y = y, x % y return x def main(): test = int(input()) for t in range(test): n = int(input()) l = [int(i) for i in input().split(" ")] c = [(0) for i in range(len(l))] num = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] color = 1 col = 1 for j in range(len(num)): flag = False for i in range(len(l)): if c[i] == 0: if l[i] % num[j] == 0: c[i] = col flag = True if flag: color = col col += 1 cl = c.count(0) if cl < 11 - color: for i in range(len(c)): if c[i] == 0: color += 1 c[i] = color print(color) for i in c: print(i, end=" ") print() main()
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR 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 STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) xx = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(t): n = int(input()) aa = list(map(int, input().split())) x = [(0) for i in range(n)] y = set() jj = 0 for i in aa: k = 1 for j in xx: if i % j == 0: ind = k y.add(k) break k += 1 x[jj] = k jj += 1 ss = {} l = 0 for i in y: l += 1 ss[i] = l print(len(y)) for i in x: print(ss[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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR 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.
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for i in range(int(input())): input() a = [ min((i + 1 for i in range(11) if a % p[i] == 0), default=10**4) for a in map(int, input().split()) ] sa = sorted(set(a)) print(len(sa)) print(*[(sa.index(x) + 1) for x in a])
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER NUMBER 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.
t = int(input()) primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] def getPrime(num): for i in range(0, 11): prime = primes[i] if num % prime == 0: return prime for _ in range(t): n = int(input()) al = list(map(int, input().split())) primeused = [] for i in range(len(al)): x = getPrime(al[i]) if x not in primeused: primeused.append(x) ans = [0] * n for i in range(n): x = getPrime(al[i]) ind = primeused.index(x) ans[i] = ind + 1 print(len(primeused)) for i in range(n - 1): print(ans[i], end=" ") print(ans[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER 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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] t = int(input()) for i in range(t): n = int(input()) numbers = [int(i) for i in input().split()] colored_primes = [-1] * 11 colors = [] color = 1 for number in numbers: for i in range(len(primes)): if number % primes[i] == 0: if colored_primes[i] == -1: colored_primes[i] = color color = color + 1 colors.append(colored_primes[i]) break print(color - 1) for c in colors: print(c, 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR 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 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.
ans = [] for _ in range(int(input())): n = int(input()) u = list(map(int, input().split())) a = [0] * n pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] dct = dict() ind = 1 for i in range(n): for j in range(11): if u[i] % pr[j] == 0: if j in dct.keys(): a[i] = dct[j] else: a[i] = ind dct[j] = ind ind += 1 break ans.append(str(max(a))) ans.append(" ".join(map(str, a))) print("\n".join(ans))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL 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.
def primeFacorize(x): p = [7, 11, 13, 17, 19, 23, 29, 31, 37] ans = [] t = 0 for i in p: if x % i == 0: t = i break return [t, x // t] for _ in range(int(input())): n = int(input()) array = list(map(int, input().split())) count = [0, 0, 0] ansarray = [] primes = {} maxV = 0 for i in array: if i % 2 == 0: if count[0] == 0: maxV += 1 count[0] = maxV ansarray.append(count[0]) elif i % 3 == 0: if count[1] == 0: maxV += 1 count[1] = maxV ansarray.append(count[1]) elif i % 5 == 0: if count[2] == 0: maxV += 1 count[2] = maxV ansarray.append(count[2]) else: pk = primeFacorize(i) if pk[0] in primes: ansarray.append(primes[pk[0]]) elif pk[1] in primes: ansarray.append(primes[pk[1]]) else: maxV += 1 primes[pk[0]] = maxV ansarray.append(maxV) print(maxV) print(*ansarray)
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR RETURN LIST VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER 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.
minPrimeDiv = [(1) for i in range(0, 1001)] for i in range(2, 1001): if minPrimeDiv[i] != 1: continue else: for j in range(i, 1001, i): if minPrimeDiv[j] == 1: minPrimeDiv[j] = i def solve(l): col = {} ans = [] for num in l: primeDiv = minPrimeDiv[num] if primeDiv not in col: tempSize = len(col) col[primeDiv] = str(tempSize + 1) ans.append(col[primeDiv]) print(len(col)) print(" ".join(ans)) t = int(input()) for i in range(0, t): input() inp = list(map(lambda x: int(x), input().split())) solve(inp)
ASSIGN VAR NUMBER VAR FUNC_CALL 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 FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR 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 NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] for tc in range(t): n = int(input()) li = [int(inp) for inp in input().split(" ")] c = set() s = "" color = [(-1) for i in range(len(primes))] nextcolor = 1 for num in li: for i, prime in enumerate(primes): if num % prime == 0: if color[i] == -1: color[i] = nextcolor nextcolor += 1 s += str(color[i]) + " " c.add(i) break print(len(c)) print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER 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 STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) for x in range(t): n = int(input()) a = list(map(int, input().split())) color_scheme = [(0) for i in range(len(a))] color = {} c = 0 for y in range(len(a)): if a[y] in color.keys(): color_scheme[y] = color[a[y]] else: for z in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]: if a[y] % z == 0: if z in color.keys(): color_scheme[y] = color[z] else: c += 1 color[z] = c color_scheme[y] = c break print(c) print(*color_scheme)
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 FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
import sys primes = "2\t3\t5\t7\t11\t13\t17\t19\t23\t29\t31".replace("\n", "\t").split("\t") primes = [int(x) for x in primes] queries = int(sys.stdin.readline()) def queryFindFences(): colors = {} count = int(sys.stdin.readline()) heights = sys.stdin.readline().strip().split() complexNeighbors = [0] * count drawed = [0] * count pos = 0 last_color = 0 for pos in range(count): height = int(heights[pos]) for prime in primes: if height % prime == 0: break try: drawed[pos] = colors[prime] except: last_color += 1 colors[prime] = str(last_color) drawed[pos] = colors[prime] print(last_color) print(" ".join(drawed)) for query in range(queries): queryFindFences()
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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.
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] q = int(input()) while q != 0: q -= 1 all_col = dict() n = int(input()) lt = [int(x) for x in input().split()] used = 1 for i in range(n): k = lt[i] j = 0 while k % pr[j] != 0: j += 1 if pr[j] in all_col: lt[i] = all_col[pr[j]] else: lt[i] = used all_col[pr[j]] = used used += 1 print(len(list(set(lt)))) print(*lt)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) for __ in range(t): n = int(input()) A = list(map(int, input().split())) groups = [[] for i in range(11)] ans = [0] * n calc = 1 fwasnt = 1 gigs = { (2): 1, (3): 2, (5): 3, (7): 4, (11): 5, (13): 6, (17): 7, (19): 8, (23): 9, (29): 10, (31): 11, } for i in range(len(A)): for key in gigs: if not A[i] % key: ans[i] = gigs[key] break was = 0 true = 1 for i in range(1, 12): for j in range(n): if ans[j] == i: was = 1 ans[j] = true true += was was = 0 print(max(ans)) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN 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()) p = [2, 3, 5, 7] for i in range(10, 38): k = 2 sqrt = i**0.5 while k <= sqrt and i % k != 0: k += 1 if k > sqrt: p.append(i) ans = [] counter = 0 for i in range(t): n = int(input()) nums = list(map(int, input().split())) now = [] for j in range(n): d = 0 while nums[j] % p[d] != 0: d += 1 if p[d] not in now: now.append(p[d]) nums[j] = now.index(p[d]) + 1 ans.append([len(now), nums]) for i in ans: print(i[0]) print(*i[1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) p = [1] * n f = [0] * n i = 2 y = max(l) while i <= y: for j in range(n): if l[j] % i == 0: if f[j] == 0: f[j] = 1 p[j] = i i += 1 print(len(set(p))) x = {} k = 1 for i in range(n): if p[i] not in x: x[p[i]] = k print(k, end=" ") k += 1 else: print(x[p[i]], end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER 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.
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) col = [0] * n d = dict() for t in range(len(a)): j = 2 isprime = True while j * j <= a[t]: if a[t] % j == 0: isprime = False break j += 1 if isprime == True: d[a[t]] = len(d) + 1 col[t] = len(d) for t in range(len(a)): if col[t] == 0: x = a[t] j = 2 fs = [] while j * j <= x: if x % j == 0: fs.append(j) while x % j == 0: x //= j j += 1 fs.append(x) ok = False for y in fs: if d.get(y) != None: col[t] = d[y] ok = True break if ok == False: d[fs[0]] = len(d) + 1 col[t] = len(d) print(len(d)) print(*col)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) for i in range(0, t, 1): n = int(input()) a = list(map(int, input().split())) b = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] c = [[], [], [], [], [], [], [], [], [], [], []] for j in range(0, len(a)): for q in range(0, 11, 1): if a[j] % b[q] == 0: c[q].append(j) break na = 1 k = [] for j in range(0, n): k.append(0) for j in range(0, 11, 1): if len(c[j]) > 0: for q in range(0, len(c[j]), 1): k[c[j][q]] = na na += 1 print(na - 1) print(*k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR 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.
import sys t = -1 def input(): global t t += 1 return d[t] d = sys.stdin.readlines() k = int(input()) p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for i in range(k): n = int(input()) a = list(map(int, input().split())) answer = [-1] * n number = [-1] * 11 count = 1 for i in range(n): for j in range(11): if a[i] % p[j] == 0: if number[j] == -1: number[j] = count count += 1 answer[i] = number[j] break print(count - 1) print(*answer)
IMPORT ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 BIN_OP LIST NUMBER NUMBER 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 NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN 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.
def prime_list(n): sieve = [True] * n m = int(n**0.5) for i in range(2, m + 1): if sieve[i] == True: for j in range(i + i, n, i): sieve[j] = False return [i for i in range(2, n) if sieve[i] == True] def answer(compositeIntegers): n = len(compositeIntegers) m = [i for i in range(12, 0, -1)] colors = [0] * n coloredElCount = 0 primes = prime_list(999) colorId = m.pop() primeIndex = 0 while coloredElCount != n: divider = primes[primeIndex] colorIsUsed = False for i in range(n): if colors[i] != 0: continue if compositeIntegers[i] % divider == 0: colors[i] = colorId coloredElCount += 1 colorIsUsed = True primeIndex = primeIndex + 1 if colorIsUsed is True: colorId = m.pop() return str(colorId - 1) + "\n" + " ".join([str(c) for c in colors]) testCount = int(input()) for _ in range(testCount): n = input() compositeIntegers = list(map(int, input().split())) print(answer(compositeIntegers))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR 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()) def primes(n): odds = range(3, n + 1, 2) sieve = set(sum([list(range(q * q, n + 1, q + q)) for q in odds], [])) return [2] + [p for p in odds if p not in sieve] for _ in range(t): input() arr = list(map(int, input().split())) s = set(arr) coloring = dict() color = 0 for prime in primes(1000): colored = False for v in list(s): if v % prime == 0: coloring[v] = color + 1 s.remove(v) colored = True if colored: color += 1 print(color) print(*[coloring[x] for x in arr])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR LIST RETURN BIN_OP LIST NUMBER VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR 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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER 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()) array = list(map(int, input().split())) result, colors, deviders, c_dict = ( [0] * n, 1, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31], {}, ) for i_elem, elem in enumerate(array): for i_devider, devider in enumerate(deviders): if elem % devider == 0: if devider not in c_dict: c_dict[devider] = colors result[i_elem] += colors colors += 1 else: result[i_elem] += c_dict[devider] break print(colors - 1) print(" ".join(list(map(str, result))))
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 VAR VAR VAR BIN_OP LIST NUMBER VAR NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER DICT FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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.
for i in range(int(input())): a = int(input()) li = list(map(int, input().split())) c = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] d = [] e = [(0) for i in range(11)] l = 1 f = [(0) for i in range(11)] for i in li: for j in range(11): if i % c[j] == 0: if f[j] == 0: f[j] = l l += 1 d.append(f[j]) break print(l - 1) print(*d)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR 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 primes1(n): sieve = [True] * (n // 2) for i in range(3, int(n**0.5) + 1, 2): if sieve[i // 2]: sieve[i * i // 2 :: i] = [False] * ((n - i * i - 1) // (2 * i) + 1) return [2] + [(2 * i + 1) for i in range(1, n // 2) if sieve[i]] primes = primes1(40) for _ in range(int(input())): n = int(input()) ai = list(map(int, input().split())) mylist = [0] * n m = 1 boolean = True for item in primes: if boolean == False: m += 1 boolean = True for items in range(n): if mylist[items] == 0: if ai[items] % item == 0: boolean = False mylist[items] = m print(max(mylist)) print(*mylist)
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER RETURN BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
import sys input = sys.stdin.readline MOD = 1000000007 MOD2 = 998244353 ii = lambda: int(input().strip("\n")) si = lambda: input() dgl = lambda: list(map(int, input().strip("\n"))) f = lambda: map(int, input().strip("\n").split()) il = lambda: list(map(int, input().strip("\n").split())) ls = lambda: list(input().strip("\n")) let = "abcdefghijklmnopqrstuvwxyz" l = [(0) for i in range(1001)] for i in range(2, 1001): if l[i] == 0: for j in range(i * 2, 1001, i): l[j] = 1 lprime = [i for i in range(2, 1001) if l[i] == 0] for _ in range(ii()): n = ii() l = il() d = dict() for i in range(n): for j in lprime: if l[i] % j == 0: if j in d: d[j].append(i) else: d[j] = [i] break it = 1 for i in d: for j in d[i]: l[j] = it it += 1 print(it - 1) print(*l)
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER 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
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())) d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] used = [0] * 11 cur = 1 c = [0] * n for j in range(n): f = 0 for k in range(11): if not f and a[j] % d[k] == 0: f = 1 if used[k] == 0: used[k] = cur cur += 1 c[j] = used[k] print(cur - 1) print(*c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN 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 I = lambda: int(input()) readline = lambda: sys.stdin.readline().strip("\n") RM = readmap = lambda x=int: map(x, readline().split(" ")) primes11 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(I()): n, l = I(), [*RM()] primes_used = {} sol = [0] * n for ind, i in enumerate(l): for prime in primes11: if i % prime == 0: if not prime in primes_used: primes_used[prime] = len(primes_used) + 1 sol[ind] = primes_used[prime] break print(len(set(sol))) print(" ".join([str(i) for i in sol])) quit() for _ in range(I()): a, b, c, d, x, y, x1, y1, x2, y2 = *RM(), *RM() flag1 = x2 - x >= b - a and x - x1 >= a - b and y2 - y >= d - c and y - y1 >= c - d flag2 = (b == 0 and a == 0 or x2 - x1 > 0) and (c == 0 and d == 0 or y2 - y1 > 0) print(["NO", "YES"][flag1 and flag2])
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR LIST FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) while t > 0: n = int(input()) x = input().split(" ") c = 1 l = [] d = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for j in x: i = int(j) if i % 2 == 0: if d[0] == 0: d[0] = c c += 1 l.append(d[0]) elif i % 3 == 0: if d[1] == 0: d[1] = c c += 1 l.append(d[1]) elif i % 5 == 0: if d[2] == 0: d[2] = c c += 1 l.append(d[2]) elif i % 7 == 0: if d[3] == 0: d[3] = c c += 1 l.append(d[3]) elif i % 11 == 0: if d[4] == 0: d[4] = c c += 1 l.append(d[4]) elif i % 13 == 0: if d[5] == 0: d[5] = c c += 1 l.append(d[5]) elif i % 17 == 0: if d[6] == 0: d[6] = c c += 1 l.append(d[6]) elif i % 19 == 0: if d[7] == 0: d[7] = c c += 1 l.append(d[7]) elif i % 23 == 0: if d[8] == 0: d[8] = c c += 1 l.append(d[8]) elif i % 29 == 0: if d[9] == 0: d[9] = c c += 1 l.append(d[9]) elif i % 31 == 0: if d[10] == 0: d[10] = c c += 1 l.append(d[10]) print(c - 1) for i in l[:-1]: print(i, end=" ") print(l[-1]) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) for _ in range(t): n = int(input()) A = [*map(int, input().split())] colors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] color_idx = {} mx_idx = 1 res = [] for a in A: for c in colors: if not a % c: if c not in color_idx: color_idx[c] = mx_idx mx_idx += 1 i = color_idx[c] res += (i,) break print(mx_idx - 1) print(" ".join(map(str, res)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR IF VAR VAR ASSIGN 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
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 main(): import sys input = sys.stdin.buffer.readline P = [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())) ans = [0] * N seen = {} k = 1 for i, a in enumerate(A): for j, p in enumerate(P): if a % p == 0: if not p in seen: seen[p] = k ans[i] = k k += 1 else: ans[i] = seen[p] break print(max(ans)) print(*ans) main()
IMPORT FUNC_DEF 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 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 DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN 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.
a = int(input()) for _ in range(a): size = int(input()) ar = list(map(int, input().split())) g = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 v = [0] * size z = [0] * 11 u = 0 for i in range(size): if ar[i] % 31 == 0: if z[0] == 0: u += 1 z[0] = u v[i] = z[0] elif ar[i] % 29 == 0: if z[1] == 0: u += 1 z[1] = u v[i] = z[1] elif ar[i] % 23 == 0: if z[2] == 0: u += 1 z[2] = u v[i] = z[2] elif ar[i] % 19 == 0: if z[3] == 0: u += 1 z[3] = u v[i] = z[3] elif ar[i] % 17 == 0: if z[4] == 0: u += 1 z[4] = u v[i] = z[4] elif ar[i] % 13 == 0: if z[5] == 0: u += 1 z[5] = u v[i] = z[5] elif ar[i] % 11 == 0: if z[6] == 0: u += 1 z[6] = u v[i] = z[6] elif ar[i] % 7 == 0: if z[7] == 0: u += 1 z[7] = u v[i] = z[7] elif ar[i] % 5 == 0: if z[8] == 0: u += 1 z[8] = u v[i] = z[8] elif ar[i] % 3 == 0: if z[9] == 0: u += 1 z[9] = u v[i] = z[9] elif ar[i] % 2 == 0: if z[10] == 0: u += 1 z[10] = u v[i] = z[10] print(u) for i in range(size): print(v[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 NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER 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.
def SieveOfEratosthenes(n): arr = [] prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0] = False prime[1] = False for p in range(n + 1): if prime[p]: arr.append(p) return arr for t in range(int(input())): n = int(input()) arr = list(map(int, input().split())) prime = SieveOfEratosthenes(max(arr)) color = 1 visited = [0] * n counter = 0 for p in prime: if counter == n: break flag = False for i in range(n): if arr[i] % p == 0 and visited[i] == 0: visited[i] = color flag = True counter += 1 if flag: color += 1 print(color - 1) for i in visited: print(i, end=" ") print()
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
MOD = 998244353 T = 1 T = int(input()) for t in range(1, T + 1): n = int(input()) a = list(map(int, input().split())) p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] colour = {i: [] for i in range(1, 12)} for i in range(n): for j in range(11): if a[i] % p[j] == 0: colour[j + 1].append(i) break c = [(0) for i in range(n)] x = 1 for i in range(1, 12): if colour[i] == []: continue for j in colour[i]: c[j] = x x += 1 print(x - 1) print(*c)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR LIST FOR 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.
from sys import stdin, stdout cin = stdin.readline cout = stdout.write mp = lambda: list(map(int, cin().split())) prime = [True] * 32 p = [] for i in range(2, 32): if prime[i]: p += [i] for j in range(i * 2, 32, i): prime[j] = False (t,) = mp() for _ in range(t): (n,) = mp() a = mp() color = [0] * n m = 0 for i in range(11): f = 0 for j in range(n): if color[j]: continue elif not a[j] % p[i]: if not f: f = 1 m += 1 color[j] = m cout(str(m) + "\n") for val in color: cout(str(val) + " ") cout("\n")
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR IF VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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.
primes = set() for i in range(2, 1001): j = 2 isprime = True while j * j <= i: if i % j == 0: isprime = True break j += 1 if isprime: primes.add(i) def solve(): unused_primes = set(primes) prime_to_c = {} c = 0 n = int(input()) arr = [int(v) for v in input().split()] ans = [] for a in arr: found = False for f, color in prime_to_c.items(): if a % f == 0: ans.append(str(color)) found = True break if not found: remove_p = 0 for p in unused_primes: if a % p == 0: remove_p = p c += 1 prime_to_c[p] = c ans.append(str(c)) break if remove_p: unused_primes.discard(remove_p) print(len(prime_to_c)) print(" ".join(ans)) t = int(input()) for _ in range(t): solve()
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL 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.
primes = [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())) colors = "" used = [0] * 11 count = 0 for ai in a: for i in range(11): if ai % primes[i] is 0: if used[i] is 0: count += 1 used[i] = count colors += str(used[i]) + " " break print("{0}\n{1}".format(count, colors))
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 STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] res = [] used_colors = [] for e in a: for i, c in enumerate(used_colors, start=1): if e % c == 0: res.append(i) break else: for c in primes: if e % c == 0: res.append(len(used_colors) + 1) used_colors.append(c) break print(len(used_colors)) print(*res)
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 LIST ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) first_11_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for i in range(t): n = int(input()) assignment = [] used = [(False) for i in range(11)] for x in map(int, input().split()): broken = False for i, prime in enumerate(first_11_primes): if x % prime == 0: assignment.append(i) used[i] = True broken = True break if not broken: print("Something wrong") print(used.count(True)) current_no = 1 for i, x in enumerate(used): if x: used[i] = current_no current_no += 1 print(" ".join(str(used[x]) for x in assignment))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
test = int(input()) for i in range(test): n = int(input()) nums = [int(i) for i in input().split(" ")] primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] color = [0] * n col = 1 for i in primes: flag = 0 enter = 0 for j in range(n): if color[j] == 0: enter = 1 if nums[j] % i == 0: color[j] = col flag = 1 if flag and enter: col += 1 print(col - 1) for i in color: print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
input = __import__("sys").stdin.readline print = __import__("sys").stdout.write for _ in range(int(input())): n = int(input()) k = list(map(int, input().split())) tmp = [(False) for _ in range(n)] prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] used = [(False) for _ in range(11)] s = set() for idx in range(n): for i in range(11): if k[idx] % prime[i] == 0: tmp[idx] = prime[i] used[i] = True break d = {} color = 1 for i in range(11): if used[i]: d[prime[i]] = color color += 1 print(f"{len(d)}\n") for i in tmp: print(f"{d[i]} ") print("\n")
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING 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 ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR 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.
import sys def input(): return sys.stdin.readline()[:-1] t = int(input()) divs = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = [] cur = 1 used = [(0) for _ in range(11)] for x in a: for i, d in enumerate(divs): if x % d == 0: if used[i] == 0: b.append(cur) used[i] = cur cur += 1 else: b.append(used[i]) break print(cur - 1) print(*b)
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER 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 NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL 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.
t = int(input()) for j in range(t): n = int(input()) a = [int(i) for i in input().split()] b = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] b1 = [0] * 11 s = 0 c = [0] * n for i in range(n): y = 0 while a[i] % b[y] != 0: y += 1 if b1[y] == 0: s += 1 b1[y] = s c[i] = b1[y] print(s) for i in range(n - 1): print(c[i], end=" ") print(c[n - 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 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR 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.
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for q in range(int(input())): cind = 0 ind = [-1] * 11 n = int(input()) ans = [0] * n d = [int(i) for i in input().split()] for i in range(n): k = d[i] for j in range(11): if k % pr[j] == 0: if ind[j] == -1: cind += 1 ind[j] = cind ans[i] = ind[j] break print(cind) print(*ans)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR 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 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.
z = int(input()) for i in range(z): n = int(input()) mas = list(map(int, input().split())) numbers = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, ] colors = [0] * n k = 0 ind = 0 ind_true = 1 r = 0 while k < n: r = 0 for i in range(n): if colors[i] == 0: if mas[i] % numbers[ind] == 0: colors[i] = ind_true k += 1 r = 1 ind += 1 if r == 1: ind_true += 1 if r == 1: ind_true -= 1 print(ind_true) print(*colors)
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 NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF 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.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] t = int(input()) for _ in range(t): n = int(input()) cs = [] c = 0 p_to_c = {} for a in input().split(): a = int(a) for i, prime in enumerate(primes): if a % prime == 0: if prime in p_to_c: cs.append(p_to_c[prime]) else: c += 1 cs.append(c) p_to_c[prime] = c break print(c) print(" ".join(map(str, cs)))
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 LIST ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
colors = [(0) for i in range(1001)] colors[0] = -1 colors[1] = -1 def isprime(n): for i in range(2, n): if n % i == 0: return False return True for c, i in enumerate([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]): for j in range(1001): if j % i == 0: colors[j] = c + 1 for _ in range(int(input())): n = int(input()) nums = [int(x) for x in input().split()] ans = [colors[i] for i in nums] setans = list(set(ans)) ncol = len(setans) ansvoc = {c: (i + 1) for i, c in enumerate(setans)} print(ncol) for n in ans: print(ansvoc[n], end=" ") print()
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR 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.
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = [int(item) for item in input().split()] d = dict() primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] group = [[] for _ in range(11)] for i, item in enumerate(a): ok = False for j, p in enumerate(primes): if item % p == 0: group[j].append(i) ok = True break if ok: continue ans = [0] * len(a) color = 1 for g in group: if not g: continue for item in g: ans[item] = color color += 1 print(color - 1) print(*ans)
IMPORT ASSIGN 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 ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR FOR 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.
c = [0] * 1001 col = 1 for i in range(2, 1001): if c[i] == 0: for j in range(i * 2, 1001, i): if c[j] == 0: c[j] = col col += 1 def tc(): n = int(input()) a = [int(x) for x in input().split()] if n <= 11: print(n) print(" ".join(map(str, range(1, n + 1)))) return ans = [c[x] for x in a] key = {k: v for k, v in zip(set(ans), range(1, 12))} ans = [key[x] for x in ans] print(len(key)) print(" ".join(map(str, ans))) T = int(input()) for _ in range(T): tc()
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FUNC_DEF 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 VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER RETURN ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
for _ in range(int(input())): l = { (2): 0, (3): 0, (5): 0, (7): 0, (11): 0, (13): 0, (17): 0, (19): 0, (23): 0, (29): 0, (31): 0, } n = int(input()) m = [int(x) for x in input().split()] x = 1 for i in range(n): for j in l: if m[i] % j == 0: if l[j] == 0: l[j] = x x += 1 m[i] = l[j] break print(x - 1) for i in range(n): print(m[i], end=" ") print()
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
from sys import stdin, stdout s = "" for _ in range(int(input())): n = int(input()) ls = list(map(int, stdin.readline().split())) pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] ans = [(0) for i in range(n)] mx = 0 f = True for i in pr: for j in range(n): if ans[j] == 0: if ls[j] % i == 0: if f: mx += 1 f = False ans[j] = mx f = True s += f"{mx}\n" for i in range(n): s += f"{ans[i]} " s += "\n" stdout.write(s)
ASSIGN VAR STRING 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) h = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(t): n = int(input()) a = list(map(int, input().split())) d = [] m = set() g = [] for i in a: for j in range(11): if i % h[j] == 0: d.append(j + 1) m.add(h[j]) break m = list(m) print(len(m)) k = 0 for i in range(11): if h[i] in m: g.append(k) else: k += 1 g.append(k) for i in range(n): d[i] -= g[d[i] - 1] print(*d)
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 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 EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR 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: n = int(input()) a = input().split() a = list(map(lambda x: int(x), a)) d = {} for i in range(n): j = 2 while j * j <= a[i]: if a[i] % j == 0: break j += 1 if j not in d: d[j] = [] d[j].append(i) ans = [(0) for i in range(n)] c = 1 for key in d: for idx in d[key]: ans[idx] = c c += 1 print(c - 1) for i in ans: print(i, end=" ") print() t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR 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.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] def fc(n): for p in primes: if n % p == 0: return p raise ValueError for _ in range(int(input())): input() arr = list(map(int, input().split())) s = set() ps = [] for e in arr: f = fc(e) s.add(f) ps.append(f) s = list(s) print(len(s)) print(*[(s.index(p) + 1) for p in ps])
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST 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 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.
N = int(input()) pr = [ 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, ] Ans = "" for i in range(N): n = int(input()) q = list(map(int, input().split())) c = [(0) for p in range(n)] l = 0 ans = "" h = 1 while 0 in c: flag = 0 for i in range(n): if q[i] % pr[l] == 0 and c[i] == 0: c[i] = h flag = 1 if flag: h += 1 l += 1 for r in range(len(c)): ans += str(c[r]) + " " Ans += str(h - 1) + "\n" + ans + "\n" print(Ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 STRING 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 ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR STRING EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
from sys import stdin input = stdin.readline q = int(input()) for rwerew in range(q): n = int(input()) l = list(map(int, input().split())) pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] odp = [] secik = set() for i in range(n): for j in range(11): if l[i] % pr[j] == 0: odp.append(j + 1) secik.add(j + 1) break print(len(secik)) d = {} num = 1 for i in secik: d[i] = num num += 1 for i in range(n): if i < n - 1: print(d[odp[i]], end=" ") else: print(d[odp[i]])
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR 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.
kek = { (2): 1, (3): 2, (5): 3, (7): 4, (11): 5, (13): 6, (17): 7, (19): 8, (23): 9, (29): 10, (31): 11, } for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) res = [] used_col = set() for el in a: for k in sorted(kek): if el % k == 0: res.append(kek[k]) used_col.add(kek[k]) break print(len(used_col)) d = {col: (i + 1) for i, col in enumerate(used_col)} for i in res: print(d[i], end=" ") print()
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR 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 FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR 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.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) k = 1 ans = [0] * n for i in range(2, 1001): f = 0 for j in range(n): if l[j] % i == 0 and ans[j] == 0: ans[j] = k f = 1 if f == 1: k += 1 print(k - 1) 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER 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.
l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(int(input())): n = int(input()) div = {} col = [0] * n m = 1 a = list(map(int, input().split())) for j in range(11): for i in range(n): if a[i] % l[j] == 0 and col[i] == 0: col[i] = m div[l[j]] = m m += 1 break for i in range(n): for j in range(len(l)): if a[i] % l[j] == 0 and col[i] == 0: col[i] = div[l[j]] break print(max(col)) print(" ".join(str(item) for item in col))
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 DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL 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 VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER 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
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
from sys import stdin, stdout t = int(stdin.readline()) for query in range(t): n = int(stdin.readline()) composites = stdin.readline().split() primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] ans = [] used = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] counter = 0 for x in range(n): ans.append(0) composites[x] = int(composites[x]) for num in range(n): for prime in range(11): if composites[num] % primes[prime] == 0: ans[num] = prime + 1 if used[prime] == 1: used[prime] = 0 break if query == 0: stdout.write("\n") stdout.write(str(used.count(0))) stdout.write("\n") z = ans[:] for x in range(11): if used[x] == 1: for y in range(n): if z[y] > x + 1: ans[y] = ans[y] - 1 for x in ans: stdout.write(str(x) + " ") stdout.write("\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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.
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(int(input())): n = int(input()) lis = list(map(int, input().split())) ans = [] for i in lis: for j in range(11): if i % prime[j] == 0: ans.append(j + 1) break k = set(ans) aa = len(k) print(aa) ans2 = [0] * n c = 1 for i in k: for j in range(n): if ans[j] == i: ans2[j] = c c += 1 print(*ans2)
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 FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR 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 int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): pp = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(II()): n = II() aa = LI() ans = [-1] * n m = 1 for p in pp: use = False for i in range(n): if ans[i] != -1 or aa[i] % p: continue use = True ans[i] = m if use: m += 1 print(max(ans)) print(*ans) main()
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING 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 RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER 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.
c = set() for i in range(1001): j = 2 while j * j <= i: if i % j == 0: while i % j == 0: i = i // j c.add(j) j += 1 if i != 1: c.add(i) c = sorted(list(c))[1:12] for test in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [[] for i in range(1001)] for i in range(n): j = 2 while j * j <= a[i]: if a[i] % j == 0: while a[i] % j == 0: a[i] = a[i] // j b[j].append(i) j += 1 if a[i] != 1: b[a[i]].append(i) used = [(-1) for i in range(n)] cnt = 0 now = 0 for i in range(2, 1001): if cnt == n: break check = True for j in range(len(b[i])): if used[b[i][j]] == -1: if check: now += 1 check = False used[b[i][j]] = now print(len(set(used))) for i in range(n): print(used[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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.
def f(A): n = len(A) C = [0] * n B = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] a = 1 for j in range(11): r = 0 for i in range(n): if A[i] % B[j] == 0 and C[i] == 0: C[i] = a r = 1 if r > 0: a += 1 print(a - 1) return C t = int(input()) while t > 0: n = int(input()) A = list(map(int, input().split())) T = f(A) for i in T: print(i, end=" ") t -= 1
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING 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.
primes = [False] * 1010 for i in range(2, 1010): n = 0 while i * (i + n) < 1010: primes[i * (i + n)] = True n += 1 final = [] for i in range(len(primes)): if not primes[i]: final.append(i) final.pop(0) final.pop(0) t = int(input()) for _ in range(t): n = int(input()) arr = [int(p) for p in input().split()] colors = [0] * n c = 0 for i in final: cnt = 0 for j in range(n): if colors[j]: continue if arr[j] % i == 0: cnt = 1 colors[j] = c + 1 if cnt: c += 1 print(max(colors)) print(*colors)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR 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 FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF 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 modifyarr(arr): for i in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]: j = i * i while j <= 1000: if arr[j] == 1: arr[j] = i j += i arr = [(1) for i in range(1001)] modifyarr(arr) t = int(input()) for you in range(t): n = int(input()) l = input().split() li = [int(i) for i in l] arrdone = [(0) for i in range(11)] for i in range(n): oi = arr[li[i]] if oi == 2: arrdone[0] = 1 if oi == 3: arrdone[1] = 1 if oi == 5: arrdone[2] = 1 if oi == 7: arrdone[3] = 1 if oi == 11: arrdone[4] = 1 if oi == 13: arrdone[5] = 1 if oi == 17: arrdone[6] = 1 if oi == 19: arrdone[7] = 1 if oi == 23: arrdone[8] = 1 if oi == 29: arrdone[9] = 1 if oi == 31: arrdone[10] = 1 lused = [] oip = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for i in range(11): if arrdone[i] == 1: lused.append(oip[i]) m = len(lused) print(m) for i in range(n): x = arr[li[i]] for j in range(m): if lused[j] == x: print(j + 1, end=" ") print()
FUNC_DEF FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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.
import sys readline = sys.stdin.readline def prsh(N): prime = [2] for L in range(3, N): for p in prime: if not L % p: break if p > L ** (1 / 2): prime.append(L) break return prime PRIME = prsh(32) pn = 11 T = int(readline()) Ans = [None] * T for qu in range(T): N = int(readline()) A = list(map(int, readline().split())) col = [0] * N used = [False] * pn for i in range(N): a = A[i] for j in range(pn): pr = PRIME[j] if not a % pr: col[i] = j used[j] = True break else: assert False, "cannot find a divisor" ncol = [0] * pn cnt = 0 for j in range(pn): if used[j]: cnt += 1 ncol[j] = cnt ans = [ncol[c] for c in col] Ans[qu] = str(cnt) + "\n" + " ".join(map(str, ans)) print("\n".join(Ans))
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR IF VAR BIN_OP VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL 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.
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]] def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors div_lis = primes(int(1000**0.5)) t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) memo = [[] for i in range(11)] for i in range(n): divisors = make_divisors(a[i]) for j in range(11): if div_lis[j] == divisors[1]: memo[j].append(i) color = [0] * n cnt = 0 for i in range(11): if len(memo[i]) > 0: cnt += 1 for j in memo[i]: color[j] = cnt print(max(color)) print(*color)
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 FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP 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 VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR 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.
I = input for _ in [0] * int(I()): I() m = 0 d = {} c = [] for x in I().split(): p = next(p for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31) if int(x) % p < 1) if (p in d) < 1: m += 1 d[p] = m c += (d[p],) print(m, *c)
ASSIGN VAR VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR 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.
t = int(input()) c = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(t): n = int(input()) a = list(map(int, input().split())) count = 0 ans = {} res = [] for i in a: for j in c: if i % j == 0: if j not in ans: count += 1 ans[j] = count res.append(ans[j]) break print(count) print(*res)
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 DICT ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR 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.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) m = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] temp = [] for i in range(n): for j in range(11): if l[i] % m[j] == 0: temp.append(m[j]) break ans = [] b = [] for i in temp: if i not in ans: ans.append(i) for i in range(len(temp)): j = 0 while 1: if temp[i] == ans[j]: break else: j += 1 b.append(j + 1) print(len(ans)) for i in b: print(i, end=" ") print(" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
import sys input = sys.stdin.readline 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())) for i in range(n): for j in range(11): if arr[i] % primes[j] == 0: arr[i] = j + 1 break S = set(arr) m = len(S) d = {s: i for i, s in enumerate(S, 1)} print(m) print(*[d[l] for l in arr])
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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER 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.
def getLowestMultiple(i): c = 2 while True: if i % c == 0: return c if c * c > i: return None c += 1 cases = int(input()) for i in range(cases): arrayLength = len(input()) numbers = [int(x) for x in input().split(" ")] numberset = set(sorted(numbers)) colours = [] for o in numberset: lowestMultiple = getLowestMultiple(o) if lowestMultiple not in colours: colours.append(lowestMultiple) print(len(colours)) print(" ".join([str(colours.index(getLowestMultiple(x)) + 1) for x in numbers]))
FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR IF BIN_OP VAR VAR VAR RETURN NONE 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 STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR 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.
def main(): t = int(input()) for __ in range(t): n = int(input()) a = list(map(int, input().split())) b = [] count = 0 color = {} for i in a: j = 2 while j * j <= i: if i % j == 0: b.append(j) if j not in color: count += 1 color[j] = count break j += 1 print(count) for i in b: print(color[i], end=" ") print() main()
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 LIST ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) def sieve(n): ass = [] 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 for i in range(n + 1): if is_prime[i]: ass.append(i) return ass P = sieve(1000) P = P[0:11] for _ in range(t): n = int(input()) A = list(map(int, input().split())) ans = [0] * n c = 1 for j in range(11): p = P[j] flag = False for i in range(n): if A[i] % p == 0 and ans[i] == 0: ans[i] = c flag = True if flag: c += 1 m = len(set(ans)) print(m) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
d = { (2): 1, (3): 2, (5): 3, (7): 4, (11): 5, (13): 6, (17): 7, (19): 8, (23): 9, (29): 10, (31): 11, (37): 12, } for _ in range(int(input())): n = int(input()) ans = [(-1) for i in range(n)] l = list(map(int, input().split())) c = 1 for i in d: f = 1 for j in range(n): if l[j] % i == 0 and ans[j] == -1: ans[j] = c f = 0 if f == 0: c += 1 print(len(set(ans))) print(*ans)
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 NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
def some(n, delims, answer, count, table): for delimIdx in range(len(delims)): if n % int(delims[delimIdx]) == 0: if delims[delimIdx] not in table: table[delims[delimIdx]] = str(count) count += 1 answer.append(table[delims[delimIdx]]) return count return count t = int(input()) for i in range(1, t + 1): W = int(input()) N = [int(x) for x in input().split()] answer = [] count = 1 table = {} delims = ["2", "3", "5", "7", "11", "13", "17", "19", "23", "29", "31"] for n in N: count = some(n, delims, answer, count, table) print(len(set(answer))) print(" ".join(answer))
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR RETURN 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] def solve(): n = int(input()) array = list(map(int, input().split())) dic = {} res = [] x = 1 for a in array: for i in range(11): if a % prime[i - 1] == 0: res.append(i) if i not in dic.keys(): dic[i] = x x += 1 break print(len(set(res))) for r in res: print(dic[r], end=" ") print() for _ in range(int(input())): solve()
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL 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 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.
t = int(input()) p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] ans = [] for i in range(0, t): n = int(input()) A = list(map(int, input().split())) answer = [(0) for i in range(0, n)] color = 1 for j in range(0, 11): flag = 0 for k in range(0, n): if answer[k] == 0 and A[k] % p[j] == 0: answer[k] = color flag = 1 color += flag ans.append([color - 1]) ans.append(answer) for i in range(0, len(ans)): print(*ans[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
def main(): primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] n = int(input()) a = [] a = list(map(int, input().split())) dp = [] dp = [(-1) for _ in range(len(primes))] cnt = 0 for i in range(len(a)): for j in range(len(primes)): if a[i] % primes[j] == 0: if dp[j] == -1: cnt += 1 dp[j] = cnt a[i] = dp[j] break print(cnt) for x in a: print(x, end=" ") t = int(input()) while t: main() print() t -= 1
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] def primefactor(n): for i in range(2, int(n**0.5 + 1)): if n % i == 0: return i return -1 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [] indices = [] for i in range(n): ind = primes.index(primefactor(a[i])) indices.append(ind) color = list(set(indices)) for elem in indices: b.append(color.index(elem) + 1) print(len(color)) print(*b)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL 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 factors(a): m = [] i = 1 while i <= a: if a % i == 0: m.append(i) i += 1 return m def common(a, b): c = 0 for i in a: if i in b: c += 1 if c > 1: return True return False t = int(input()) for q in range(t): n = int(input()) l = list(map(int, input().split())) m = [] for i in l: m.append(factors(i)) count = 1 colors = [0] * n prime = [] for i in m: prime.append(i[1]) nums = sorted(list(set(prime))) count = 1 pos = 0 while 0 in colors: for i in range(0, len(prime)): if prime[i] == nums[pos]: colors[i] = count count += 1 pos += 1 print(count - 1) y = "" for i in colors: y += str(i) y += " " print(y)
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER RETURN 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 LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(int(input())): input() seq = [int(x) for x in input().split()] ans = [(0) for _ in range(len(seq))] m = 0 cmap = {} for i in range(len(seq)): for c, p in enumerate(pr): if seq[i] % p == 0: if c not in cmap: m += 1 cmap[c] = str(m) ans[i] = cmap[c] break print(m) print(" ".join(x for x in ans))
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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()) p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for x in range(t): n = int(input()) a = list(map(int, input().split())) k = [] for i in range(n): for g in range(len(p)): if len(k) == i and a[i] % p[g] == 0: k.append(p[g]) dif = [] for i in range(n): if not k[i] in dif: dif.append(k[i]) print(len(dif)) q = "" for i in range(n): for g in range(len(dif)): if k[i] == dif[g]: q = q + str(g + 1) + " " print(q[:-1])
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 FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choose an integer m ≀ 11 and color each element one of m colors from 1 to m so that: * for each color from 1 to m there is at least one element of this color; * each element is colored and colored exactly one color; * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. Note that equal elements can be colored different colors β€” you just have to choose one of m colors for each of the indices from 1 to n. Alice showed already that if all a_i ≀ 1000 then she can always solve the task by choosing some m ≀ 11. Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer n (1 ≀ n ≀ 1000) β€” the amount of numbers in a sequence a. The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≀ a_i ≀ 1000). It is guaranteed that the sum of n over all test cases doesn't exceed 10^4. Output For each test case print 2 lines. The first line should contain a single integer m (1 ≀ m ≀ 11) β€” the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11. Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1). Example Input 3 3 6 10 15 2 4 9 23 437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961 Output 1 1 1 1 2 2 1 11 4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6 Note In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case. In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
t = int(input()) sosu = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] for _ in range(t): n = int(input()) a = list(map(int, input().split())) ans = [] ans2 = 0 for i in range(n): for j in range(11): if a[i] % sosu[j] == 0: ans.append(j + 1) ans2 = max(j + 1, ans2) break used = [1] * ans2 for x in ans: used[x - 1] = 0 for i in range(ans2 - 1): used[i + 1] += used[i] for i in range(n): ans[i] -= used[ans[i] - 1] print(ans2 - used[-1]) 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 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 BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR