#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long f = 1, ans = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + c -  0 ;       c = getchar();     }     return f * ans;   }   const long long MAXN = 4e5 + 11;   long long phi[MAXN], N, A[MAXN], id[MAXN], pri[MAXN], mu[MAXN], v[MAXN],       inv[MAXN], V[MAXN];   vector<long long> vec[MAXN], Vec[MAXN];   void Init() {     mu[1] = 1, phi[1] = 1;     V[1] = 1;     for (long long i = 2; i <= N; i++) {       if (!v[i]) {         pri[++pri[0]] = i, v[i] = i, mu[i] = -1, phi[i] = i - 1;         V[i] = inv[i - 1] * i % 1000000007;       }       for (long long j = 1; j <= pri[0] && i <= N / pri[j]; j++) {         v[i * pri[j]] = pri[j];         if (!(i % pri[j])) {           phi[i * pri[j]] = phi[i] * pri[j];           V[i * pri[j]] = V[i];           mu[i * pri[j]] = 0;           break;         }         phi[i * pri[j]] = phi[i] * (pri[j] - 1);         mu[i * pri[j]] = -mu[i];         V[i * pri[j]] = V[i] * V[pri[j]] % 1000000007;       }     }     return;   }   long long ksm(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans *= a, ans %= 1000000007;       a *= a, a %= 1000000007;       b >>= 1;     }     return ans;   }   long long in[MAXN], out[MAXN], rev[MAXN], dep[MAXN], tot, Log[MAXN], F[MAXN],       sta[MAXN], Q[MAXN], q[MAXN], f[MAXN];   vector<long long> C;   void dfs(long long u, long long fath) {     in[u] = ++tot, rev[tot] = u, dep[u] = dep[fath] + 1;     for (auto v : vec[u])       if (v != fath) {         dfs(v, u);         rev[++tot] = u;       }     out[u] = tot;   }   bool cmp(long long x, long long y) { return in[x] < in[y]; }   struct RMQ {     long long Minn[MAXN][21], ps[MAXN][21];     void init() {       for (long long i = 1; i <= tot; i++)         Minn[i][0] = dep[rev[i]], ps[i][0] = rev[i];       for (long long j = 1; (1 << j) <= tot; j++)         for (long long i = 1; i + (1 << j) - 1 <= tot; i++) {           if (Minn[i][j - 1] <= Minn[i + (1 << (j - 1))][j - 1])             Minn[i][j] = Minn[i][j - 1], ps[i][j] = ps[i][j - 1];           else             Minn[i][j] = Minn[i + (1 << (j - 1))][j - 1],             ps[i][j] = ps[i + (1 << (j - 1))][j - 1];         }       return;     }     long long Qlca(long long u, long long v) {       if (in[u] > in[v]) swap(u, v);       long long L = in[u], R = in[v], len = R - L + 1, k = Log[len];       long long w1 = Minn[L][k], w2 = Minn[R - (1 << k) + 1][k];       if (w1 <= w2) return ps[L][k];       return ps[R - (1 << k) + 1][k];     }   } S;   void ins(long long x) {     if (sta[0] == 1) {       if (sta[1] != x) sta[++sta[0]] = x;       return;     }     long long now = S.Qlca(x, sta[sta[0]]);     while (sta[0] > 1 && dep[sta[sta[0] - 1]] >= dep[now])       Vec[sta[sta[0] - 1]].push_back(sta[sta[0]]), sta[0]--;     if (dep[sta[sta[0]]] > dep[now]) Vec[now].push_back(sta[sta[0]]), sta[0]--;     if (sta[sta[0]] != now) sta[++sta[0]] = now;     sta[++sta[0]] = x;     return;   }   void build() {     sta[0] = 0;     sta[++sta[0]] = 1;     for (long long i = 1; i <= Q[0]; i++) ins(Q[i]);     while (sta[0] > 1) Vec[sta[sta[0] - 1]].push_back(sta[sta[0]]), sta[0]--;     return;   }   long long S1[MAXN], S2[MAXN], res, D;   void Clear() {     for (auto v : C) Vec[v].clear(), S1[v] = S2[v] = 0;     C.clear();     return;   }   void dfs1(long long u) {     long long now1 = 0, now2 = 0;     C.push_back(u);     for (auto v : Vec[u]) {       dfs1(v);       if (!(A[u] % D))         now2 += (S1[v] * phi[A[u]]) % 1000000007,             now2 -= phi[A[u]] * S2[v] % 1000000007 * dep[u] % 1000000007,             now2 = ((now2 % 1000000007) + 1000000007) % 1000000007;       now1 -= 2 * dep[u] * S2[u] % 1000000007 * S2[v] % 1000000007,           now1 = (now1 % 1000000007 + 1000000007) % 1000000007;       now1 += S1[u] * S2[v], now1 += S2[u] * S1[v], now1 %= 1000000007;       S1[u] += S1[v], S2[u] += S2[v];       S1[u] %= 1000000007, S2[u] %= 1000000007;     }     if (!(A[u] % D)) S1[u] += dep[u] * phi[A[u]] % 1000000007, S2[u] += phi[A[u]];     S1[u] %= 1000000007, S2[u] %= 1000000007;     res += (now1 + now2) * 2 % 1000000007;     return;   }   signed main() {     N = read();     for (long long i = 1; i <= N; i++) A[i] = read(), id[A[i]] = i;     inv[1] = 1;     for (long long i = 2; i <= N; i++)       inv[i] = (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;     for (long long i = 1; i < N; i++) {       long long u = read(), v = read();       vec[u].push_back(v), vec[v].push_back(u);     }     Init();     dfs(1, 0);     Log[0] = -1;     for (long long i = 1; i <= tot; i++) Log[i] = Log[i >> 1] + 1;     S.init();     for (long long i = 1; i <= N; i++) {       D = i;       Q[0] = 0, sta[0] = 0;       bool ff = 0;       for (long long j = i; j <= N; j += i) Q[++Q[0]] = id[j];       sort(Q + 1, Q + Q[0] + 1, cmp);       build();       res = 0;       dfs1(1);       F[i] = res;       Clear();     }     for (long long i = 1; i <= N; i++)       for (long long j = i; j <= N; j += i)         f[i] += mu[j / i] * F[j],             f[i] = (f[i] % 1000000007 + 1000000007) % 1000000007;     long long Ans = 0;     for (long long i = 1; i <= N; i++) Ans += V[i] * f[i], Ans %= 1000000007;     printf( %lld n ,            Ans * ksm(N * (N - 1) % 1000000007, 1000000007 - 2) % 1000000007);     return 0;   }