def generateSeq(n):
sets = [set() for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(i, n + 1, i):
sets[i].add(j)
return sets
def EmPlusOne(n, m, sets):
for i in range(1, m + 1):
operation = list(map(int, input().split()))
index = n + i
if operation[0] == 1:
x, y = operation[1], operation[2]
sets.append(sets[x] | sets[y])
elif operation[0] == 2:
x, y = operation[1], operation[2]
sets.append(sets[x] & sets[y])
elif operation[0] == 3:
x = operation[1]
sets.append(set(range(1, n + 1)) - sets[x])
def main():
n, m, q = map(int, input().split())
sets = generateSeq(n) + [set() for _ in range(m)]
EmPlusOne(n, m, sets)
output = []
for _ in range(q):
x, v = map(int, input().split())
output.append("TAK" if v in sets[x] else "NIE")
print("\n".join(output))
if __name__ == "__main__":
main()
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 | def generateSeq(n): sets = [set() for _ in range(n + 1)] for i in range(1, n + 1): for j in range(i, n + 1, i): sets[i].add(j) return sets def EmPlusOne(n, m, sets): for i in range(1, m + 1): operation = list(map(int, input().split())) index = n + i if operation[0] == 1: x, y = operation[1], operation[2] sets.append(sets[x] | sets[y]) elif operation[0] == 2: x, y = operation[1], operation[2] sets.append(sets[x] & sets[y]) elif operation[0] == 3: x = operation[1] sets.append(set(range(1, n + 1)) - sets[x]) def main(): n, m, q = map(int, input().split()) sets = generateSeq(n) + [set() for _ in range(m)] EmPlusOne(n, m, sets) output = [] for _ in range(q): x, v = map(int, input().split()) output.append("TAK" if v in sets[x] else "NIE") print("\n".join(output)) if __name__ == "__main__": main() |
English