func_code_string: #include <bits/stdc++.h>   using namespace std;   long long int spf[100001];   void sieve();   set<long long int> factors(long long int x);   void getZarr(string str, long long int Z[]);   int n;   vector<int> ans;   vector<bool> vis;   vector<int> mas;   vector<int> del;   vector<int> koll;   vector<vector<int>> edges;   int nod(int a, int b) {     if (b == 0) return a;     return nod(b, a % b);   }   void dfs1(int v) {     vis[v] = 1;     for (auto u : edges[v])       if (!vis[u]) {         ans[u] = nod(ans[v], mas[u]);         dfs1(u);       }   }   void dfs2(int v, int dist) {     vis[v] = 1;     for (int i = 0; i < del.size(); i++) {       koll[i] += (mas[v] % del[i] == 0);       if (koll[i] >= dist) ans[v] = max(ans[v], del[i]);     }     for (auto u : edges[v])       if (!vis[u]) dfs2(u, dist + 1);     for (int i = 0; i < del.size(); i++) koll[i] -= (mas[v] % del[i] == 0);   }   signed main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     ans.resize(n);     vis.resize(n);     mas.resize(n);     edges.resize(n);     for (int i = 0; i < n; i++) cin >> mas[i];     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       edges[a].push_back(b);       edges[b].push_back(a);     }     int p = mas[0];     mas[0] = 0;     ans[0] = 0;     dfs1(0);     mas[0] = p;     for (int i = 0; i < n; i++) vis[i] = 0;     for (int i = 1; i * i <= mas[0]; i++) {       if (mas[0] % i == 0) {         del.push_back(i);         del.push_back(mas[0] / i);         if (i * i == mas[0]) del.pop_back();       }     }     sort(del.begin(), del.end());     koll.resize(del.size());     dfs2(0, 0);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }   void sieve() {     spf[1] = 1;     for (long long int i = 2; i < 100001; i++) spf[i] = i;     for (long long int i = 4; i < 100001; i += 2) spf[i] = 2;     for (long long int i = 3; i * i < 100001; i++) {       if (spf[i] == i) {         for (long long int j = i * i; j < 100001; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   void getZarr(string str, long long int Z[]) {     long long int n = str.length();     long long int L, R, k;     L = R = 0;     for (long long int i = 1; i < n; ++i) {       if (i > R) {         L = R = i;         while (R < n && str[R - L] == str[R]) R++;         Z[i] = R - L;         R--;       } else {         k = i - L;         if (Z[k] < R - i + 1)           Z[i] = Z[k];         else {           L = i;           while (R < n && str[R - L] == str[R]) R++;           Z[i] = R - L;           R--;         }       }     }   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   