#include <bits/stdc++.h>
const int maxn = 200010, maxf = 870010, mod = 1000000007;
int n, minp[maxn], a[maxn], s[maxn], sum;
int facts[maxf], *iter = facts, *fact[maxn], *last[maxn];
long long f[maxn];
long long inv(int a, int p = mod) {
  return a == 1 ? 1 : (1 + p * (a - inv(p % a, a))) / a % p;
}
void dfs(int x, int y) {
  if (x > 1)
    dfs(x / minp[x], y), dfs(x / minp[x], y * minp[x]);
  else
    *(iter++) = y;
}
struct edge {
  int to;
  edge* next;
} E[maxn * 2], *ne = E, *first[maxn];
void link(int x, int y) {
  *ne = (edge){y, first[x]};
  first[x] = ne++;
}
bool vis[maxn];
int Q[maxn], fa[maxn], siz[maxn], dep[maxn], cid[maxn], val0[maxn], val1[maxn];
void solve(int g) {
  int *h = Q, *t = Q + 1;
  fa[*Q = g] = 0;
  for (; h < t; siz[*(h++)] = 1)
    for (edge* e = first[*h]; e; e = e->next)
      if (!vis[e->to] && e->to != fa[*h]) fa[*(t++) = e->to] = *h;
  for (g = 0; h-- > Q; siz[fa[*h]] += siz[*h])
    if (t - Q - siz[*h] <= t - Q >> 1) {
      bool fl = 1;
      for (edge* e = first[*h]; e; e = e->next)
        if (!vis[e->to] && e->to != fa[*h])
          siz[e->to] > t - Q >> 1 ? fl = 0 : 1;
      if (fl) g = *h;
    }
  vis[g] = 1;
  int ccnt = 0, *i;
  h = t = Q + 1, fa[*Q = g] = dep[g] = cid[g] = 0;
  for (edge* e0 = first[g]; e0; e0 = e0->next)
    if (!vis[e0->to] && e0->to != fa[g])
      for (fa[*(t++) = e0->to] = g, dep[*h] = 1, cid[*h] = ++ccnt; h < t; h++)
        for (edge* e = first[*h]; e; e = e->next)
          if (!vis[e->to] && e->to != fa[*h])
            fa[*(t++) = e->to] = *h, dep[e->to] = dep[*h] + 1,
                        cid[e->to] = cid[*h];
  for (h = Q; h < t; h = i) {
    for (i = h; i < t && cid[*i] == cid[*h]; i++) {
      long long tmp0 = 0, tmp1 = 0;
      int k = 0;
      for (int *j = fact[s[*i]], *las = last[s[*i]]; j < las; j++) {
        tmp0 += f[*j] * val0[*j];
        tmp1 += f[*j] * val1[*j];
        ++k & 7 ? 1 : (tmp0 %= mod, tmp1 %= mod);
      }
      tmp0 %= mod, tmp1 %= mod;
      sum = (sum + (tmp0 * dep[*i] + tmp1) % mod * a[*i]) % mod;
    }
    for (i = h; i < t && cid[*i] == cid[*h]; i++) {
      int tmp0 = a[*i], tmp1 = 1ll * tmp0 * dep[*i] % mod;
      for (int *j = fact[s[*i]], *las = last[s[*i]]; j < las; j++)
        (val0[*j] += tmp0) %= mod, (val1[*j] += tmp1) %= mod;
    }
  }
  for (i = Q; i < t; i++)
    for (int *j = fact[s[*i]], *las = last[s[*i]]; j < las; j++)
      val0[*j] = val1[*j] = 0;
  for (edge* e = first[g]; e; e = e->next)
    if (!vis[e->to] && e->to != fa[g]) solve(e->to);
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++)
    if (!minp[i])
      for (int j = i; j <= n; j += i)
        if (!minp[j]) minp[j] = i;
  for (int i = 1; i <= n; i++)
    f[i] = i > 1 ? i / minp[i] % minp[i]
                       ? f[i / minp[i]] * minp[i] % mod * inv(minp[i] - 1) % mod
                       : 0
                 : 1;
  for (int i = 1; i <= n; i++)
    if (f[i]) {
      fact[i] = iter;
      dfs(i, 1);
      last[i] = iter;
      for (int *j = fact[i], *las = last[i]; j < las; j++)
        if (*j < i) (f[i] += mod - f[*j]) %= mod;
    }
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    s[i] = 1;
    for (int x = a[i], p = minp[x]; p; p = minp[x]) {
      for (s[i] *= p; x % p == 0; x /= p)
        ;
      a[i] = a[i] / p * (p - 1);
    }
  }
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), link(x, y), link(y, x);
  solve(1);
  sum = sum * inv(n * (n - 1ll) / 2 % mod) % mod;
  printf("%d\n", sum);
}
