func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5;   int n, q;   int all;   int pre[2 * MaxN + 5], last[MaxN + 5], other[2 * MaxN + 5];   int node[MaxN + 5];   int father[MaxN + 5];   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   void build(int x, int y) {     pre[++all] = last[x];     last[x] = all;     other[all] = y;   }   void Dfs(int x, int fa) {     father[x] = fa;     int ed = last[x], dr;     while (ed != -1) {       dr = other[ed];       if (dr != fa) {         Dfs(dr, x);       }       ed = pre[ed];     }   }   int main() {     while (scanf( %d %d , &n, &q) != EOF) {       all = -1;       memset(last, -1, sizeof(last));       for (int i = 1; i <= n; i++) scanf( %d , &node[i]);       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d %d , &u, &v);         build(u, v);         build(v, u);       }       Dfs(1, 0);       for (int i = 1; i <= q; i++) {         int op;         scanf( %d , &op);         if (op == 1) {           int v;           int ans = -1;           scanf( %d , &v);           int now = v;           while (father[v] != 0) {             v = father[v];             if (gcd(node[v], node[now]) > 1) {               ans = v;               break;             }           }           printf( %d n , ans);         } else {           int v, w;           scanf( %d %d , &v, &w);           node[v] = w;         }       }     }     return 0;   }   