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
#include <bits/stdc++.h>

using namespace std;

const int nmax = 50 * 1024;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<bitset<nmax>> bs(n + m + 1);

    for(int i = 1; i <= n; i++) {
        auto &b = bs[i];
        for(int j = i; j <= n; j += i) {
            b[j] = 1;
        }
    }

    for(int i = n + 1; i <= n + m; i++) {
        auto& b = bs[i];
        int t; cin >> t;
        if(t == 1) {
            int x, y; cin >> x >> y;
            b = bs[x] | bs[y];
        }
        if(t == 2) {
            int x, y; cin >> x >> y;
            b = bs[x] & bs[y];
        }
        if(t == 3) {
            int x; cin >> x;
            b = ~bs[x];
        }
    }

    for(int i = 1; i <= q; i++) {
        int x, y; cin >> x >> y;
        cout << (bs[x][y] ? "TAK" : "NIE") << '\n';
    }
}