-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsub.py
More file actions
52 lines (38 loc) · 1.08 KB
/
Copy pathsub.py
File metadata and controls
52 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from functools import lru_cache, reduce
@lru_cache
def _gcd(x, y):
while y:
x, y = y, x % y
return abs(x)
def _gcd_array(a: list):
return reduce(lambda v, e: _gcd(v, e), a, a[0])
def _gcd_array_add_e(a, gcd, e):
return _gcd(gcd, a[e])
def _gcd_array_del_e(a, gcd, e):
return _gcd_array(a)
def _iterate(n):
x = 2 ** (n)
for s in range(x):
s = str(bin(s))[2:]
s = s.zfill(n)
yield s
def generate(a):
for x in _iterate(len(a)):
if x == "0" * len(a) or x == "1" * len(a):
continue
gcd1 = _gcd_array([a[i] for i in range(len(a)) if x[i] == "1"])
gcd2 = _gcd_array([a[i] for i in range(len(a)) if x[i] == "0"])
if gcd1 != gcd2:
return True, [int(v) + 1 for v in x]
return False, []
if __name__ == "__main__":
n = int(input().rstrip())
for i in range(n):
_ = input()
a = list([int(x) for x in input().rstrip().split()])
res = generate(a)
if res[0]:
print("YES")
print(*res[1])
else:
print("NO")