// ~~ icebear love attttt ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, a[N];
vector<int> G[N];
int par[N][19], h[2][N];
vector<int> values[N];
bool active[N], vis[2][N];
int root;
void dfs(int u, int type) {
if (h[type][u] > h[type][root]) root = u;
vis[type][u] = true;
for(int v : G[u]) if (!vis[type][v] && active[v]) {
h[type][v] = h[type][u] + 1;
dfs(v, type);
}
}
void init(void) {
cin >> n;
FOR(i, 1, n) {
cin >> a[i];
for(int j = 1; j * j <= a[i]; j++) if (a[i] % j == 0) {
if (j > 1) values[j].pb(i);
if (j * j != a[i]) values[a[i] / j].pb(i);
}
}
FOR(i, 2, n) {
int u, v;
cin >> u >> v;
G[u].pb(v);
G[v].pb(u);
}
}
void process(void) {
int ans = 0;
FOR(i, 2, N - 5) if (!values[i].empty()) {
for(int x : values[i]) active[x] = true;
for(int x : values[i]) if (!vis[0][x]) {
root = 0;
dfs(x, 0);
dfs(root, 1);
maximize(ans, h[1][root] + 1);
}
for(int x : values[i]) {
h[0][x] = h[1][x] = 0;
vis[0][x] = vis[1][x] = active[x] = false;
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
Ly8gfn4gaWNlYmVhciBsb3ZlIGF0dHR0dCB+fgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50LCBpbnQ+IGlpOwp0eXBlZGVmIHBhaXI8aW50LCBpaT4gaWlpOwoKdGVtcGxhdGU8Y2xhc3MgVD4KICAgIGJvb2wgbWluaW1pemUoVCAmYSwgY29uc3QgVCAmYikgewogICAgICAgIGlmIChhID4gYikgcmV0dXJuIGEgPSBiLCB0cnVlOwogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCnRlbXBsYXRlPGNsYXNzIFQ+CiAgICBib29sIG1heGltaXplKFQgJmEsIGNvbnN0IFQgJmIpIHsKICAgICAgICBpZiAoYSA8IGIpIHJldHVybiBhID0gYiwgdHJ1ZTsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICB9CgojZGVmaW5lIEZPUihpLGEsYikgZm9yKGludCBpPShhKTsgaTw9KGIpOyArK2kpCiNkZWZpbmUgRk9SUihpLGEsYikgZm9yKGludCBpPShhKTsgaT49KGIpOyAtLWkpCiNkZWZpbmUgUkVQKGksIG4pIGZvcihpbnQgaT0wOyBpPChuKTsgKytpKQojZGVmaW5lIFJFRChpLCBuKSBmb3IoaW50IGk9KG4pLTE7IGk+PTA7IC0taSkKI2RlZmluZSBNQVNLKGkpICgxTEwgPDwgKGkpKQojZGVmaW5lIEJJVChTLCBpKSAoKChTKSA+PiAoaSkpICYgMSkKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCksIHguZW5kKCk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wcm9jZXNzKHZvaWQpIHsKICAgIGludCBhbnMgPSAwOwogICAgRk9SKGksIDIsIE4gLSA1KSBpZiAoIXZhbHVlc1tpXS5lbXB0eSgpKSB7CiAgICAgICAgZm9yKGludCB4IDogdmFsdWVzW2ldKSBhY3RpdmVbeF0gPSB0cnVlOwogICAgICAgIGZvcihpbnQgeCA6IHZhbHVlc1tpXSkgaWYgKCF2aXNbMF1beF0pIHsKICAgICAgICAgICAgcm9vdCA9IDA7CiAgICAgICAgICAgIGRmcyh4LCAwKTsKICAgICAgICAgICAgZGZzKHJvb3QsIDEpOwogICAgICAgICAgICBtYXhpbWl6ZShhbnMsIGhbMV1bcm9vdF0gKyAxKTsKICAgICAgICB9CiAgICAgICAgZm9yKGludCB4IDogdmFsdWVzW2ldKSB7CiAgICAgICAgICAgIGhbMF1beF0gPSBoWzFdW3hdID0gMDsKICAgICAgICAgICAgdmlzWzBdW3hdID0gdmlzWzFdW3hdID0gYWN0aXZlW3hdID0gZmFsc2U7CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBhbnM7Cn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgaWYgKGZvcGVuKHRhc2siLmlucCIsICJyIikpIHsKICAgICAgICBmcmVvcGVuKHRhc2siLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4odGFzayIub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQogICAgaW50IHRjID0gMTsKLy8gICAgY2luID4+IHRjOwogICAgd2hpbGUodGMtLSkgewogICAgICAgIGluaXQoKTsKICAgICAgICBwcm9jZXNzKCk7CiAgICB9CiAgICByZXR1cm4gMDsKfQoK