func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int M = 1e3 + 10;   const long long mod = 1e9 + 7;   const long long inf = 1e18 + 10;   int a[N], st[N], ft[N], ind[N], lzy[4 * N], t, n, m;   vector<int> adj[N];   bitset<M> seg[4 * N], P, res, one;   void dfs(int v, int p) {     st[v] = t;     ind[t++] = v - 1;     for (int u : adj[v])       if (u != p) dfs(u, v);     ft[v] = t;   }   void build(int l = 0, int r = n, int id = 1) {     if (r - l == 1) {       seg[id][a[ind[l]]] = 1;       return;     }     int mid = (l + r) / 2;     build(l, mid, 2 * id);     build(mid, r, 2 * id + 1);     seg[id] = seg[2 * id] | seg[2 * id + 1];   }   void shift(int id) {     int x = lzy[id];     seg[2 * id] = (seg[2 * id] << x) & one | (seg[2 * id] >> (m - x));     seg[2 * id + 1] = (seg[2 * id + 1] << x) & one | (seg[2 * id + 1] >> (m - x));     lzy[2 * id] = (lzy[2 * id] + x) % m;     lzy[2 * id + 1] = (lzy[2 * id + 1] + x) % m;     lzy[id] = 0;   }   void upd(int l, int r, int x, int s = 0, int e = n, int id = 1) {     if (e <= l || r <= s) return;     if (l <= s && e <= r) {       seg[id] = (seg[id] << x) & one | (seg[id] >> (m - x));       lzy[id] = (lzy[id] + x) % m;       return;     }     shift(id);     int mid = (s + e) / 2;     upd(l, r, x, s, mid, 2 * id);     upd(l, r, x, mid, e, 2 * id + 1);     seg[id] = seg[2 * id] | seg[2 * id + 1];   }   void get(int l, int r, int s = 0, int e = n, int id = 1) {     if (e <= l || r <= s) return;     if (l <= s && e <= r) {       res |= seg[id];       return;     }     shift(id);     int mid = (s + e) / 2;     get(l, r, s, mid, 2 * id);     get(l, r, mid, e, 2 * id + 1);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i], a[i] %= m;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     build();     for (int i = 2; i < m; i++) P[i] = 1;     for (int i = 2; i < m; i++)       if (P[i])         for (int j = i * i; j < m; j += i) P[j] = 0;     for (int i = 0; i < m; i++) one[i] = 1;     int q;     cin >> q;     while (q--) {       int typ;       cin >> typ;       if (typ == 1) {         int v, x;         cin >> v >> x;         x %= m;         upd(st[v], ft[v], x);       } else {         int v;         cin >> v;         res &= 0;         get(st[v], ft[v]);         cout << (res & P).count() <<   n ;       }     }     return 0;   }   