func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<vector<int>> adj;   vector<int> a;   vector<int> dep;   vector<int> ret;   unordered_map<int, vector<int>> pmp;   unordered_map<int, vector<int>> mp;   vector<int> primeFactors(int num) {     vector<int> ret;     for (int i = 2; i * i <= num; i++) {       while (num % i == 0) {         ret.push_back(i);         num /= i;       }     }     if (num != 1) ret.push_back(num);     return ret;   }   void dfs(int idx, int prev, int level) {     dep[idx] = level;     for (int i : pmp[a[idx]]) {       if (mp.count(i) && !mp[i].empty()) {         if (ret[idx] == -1 || dep[ret[idx]] < dep[mp[i].back()])           ret[idx] = mp[i].back();       }     }     for (int i : pmp[a[idx]]) {       mp[i].push_back(idx);     }     for (auto nidx : adj[idx]) {       if (nidx == prev) continue;       dfs(nidx, idx, level + 1);     }     for (int i : pmp[a[idx]]) {       mp[i].pop_back();     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, q;     cin >> n >> q;     a = vector<int>(n + 1, 0);     dep = vector<int>(n + 1, 0);     ret = vector<int>(n + 1, -1);     for (int i = 1; i <= n; i++) cin >> a[i];     adj = vector<vector<int>>(n + 1);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (pmp.count(a[i])) continue;       pmp[a[i]] = primeFactors(a[i]);     }     dfs(1, 0, 1);     while (q--) {       int type, v, w;       cin >> type;       if (type == 1) {         cin >> v;         cout << ret[v] << endl;       } else {         cin >> v >> w;         a[v] = w;         if (pmp.count(a[v])) continue;         pmp[a[v]] = primeFactors(a[v]);         ret = vector<int>(n + 1, -1);         dfs(1, 0, 1);       }     }     return 0;   }   