func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 2, MAX2 = 2e6 + 4;   int ans[MAX], val[MAX], depth[MAX];   vector<int> G[MAX], d[MAX2], occ[MAX2];   void init(int a) {     if (d[a].size()) return;     for (int i = 2; i * i <= a; i++) {       if (a % i == 0) {         d[a].push_back(a / i);         if (i * i != a) d[a].push_back(i);       }     }     if (a != 1) d[a].push_back(a);   }   void dfs(int vv, int par, int dv = 0) {     ans[vv] = -1, depth[vv] = dv;     int v = val[vv];     for (int i = 0; i < d[v].size(); i++) {       int u = d[v][i];       if (not occ[u].empty()) {         int x = occ[u].back();         if (ans[vv] == -1 or depth[ans[vv]] < depth[x]) ans[vv] = x;       }       occ[u].push_back(vv);     }     for (int i = 0; i < G[vv].size(); i++) {       int u = G[vv][i];       if (u == par) continue;       dfs(u, vv, dv + 1);     }     for (int i = 0; i < d[v].size(); i++) {       int u = d[v][i];       occ[u].pop_back();     }   }   int main() {     int n, q;     cin >> n >> q;     for (int i = 1; i < n + 1; i++) {       scanf( %d , val + i);       init(val[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     dfs(1, 0);     while (q--) {       int type;       scanf( %d , &type);       if (type == 1) {         int x;         scanf( %d , &x);         printf( %d n , ans[x]);       } else {         int x, v;         scanf( %d %d , &x, &v);         val[x] = v;         init(val[x]);         dfs(1, 0);       }     }     return 0;   }   