#include <bits/stdc++.h>
using namespace std;
int n, a[666666], p[666666], g[666666], h[666666];
vector<int> ys[666666];
int M = 0, fst[666666], vb[666666], nxt[666666];
void ad_de(int a, int b) {
  ++M;
  nxt[M] = fst[a];
  fst[a] = M;
  vb[M] = b;
}
void adde(int a, int b) {
  ad_de(a, b);
  ad_de(b, a);
}
int d[666666], sz[666666], son[666666];
void dfs(int x, int f = 0) {
  d[x] = d[f] + 1;
  sz[x] = 1;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) {
      dfs(b, x);
      sz[x] += sz[b];
      if (sz[b] > sz[son[x]]) son[x] = b;
    }
}
const int MOD = 1e9 + 7;
long long s0[666666], s1[666666], cp[666666];
int cr;
long long ans = 0;
void clr(int x) {
  for (auto s : ys[a[x]]) s0[s] = s1[s] = 0;
}
void ins(int x) {
  for (auto s : ys[a[x]])
    (s0[s] += p[a[x]] * (long long)h[s]) %= MOD,
        (s1[s] += p[a[x]] * (long long)h[s] % MOD * d[x]) %= MOD;
}
void upd(int x) {
  for (auto s : ys[a[x]])
    ans += (s1[s] + s0[s] * (long long)(d[x] - cr)) % MOD * p[a[x]], ans %= MOD;
}
int skip = 0;
template <void (*func)(int)>
void edt(int x, int f) {
  func(x);
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f && b != skip) edt<func>(b, x);
}
void dd(int x, int f = 0, bool kep = 0) {
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f && b != son[x]) dd(b, x);
  if (son[x]) dd(son[x], x, 1), skip = son[x];
  cr = d[x] * 2;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f && b != son[x]) edt<upd>(b, x), edt<ins>(b, x);
  upd(x);
  ins(x);
  skip = 0;
  if (!kep) edt<clr>(x, f);
}
long long qp(long long a, long long b) {
  long long x = 1;
  a %= MOD;
  while (b) {
    if (b & 1) x = x * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return x;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= max(n, 10); ++i) {
    int j = i, t = i;
    for (int s = 2; s * s <= j; ++s)
      if (j % s == 0) {
        t = t / s * (s - 1);
        while (j % s == 0) j /= s;
      }
    if (j > 1) t = t / j * (j - 1);
    p[i] = t;
    g[i] = i * qp(p[i], MOD - 2) % MOD;
  }
  for (int i = 1; i <= n; ++i) h[i] = g[i];
  for (int i = 1; i <= n; ++i)
    for (int j = i + i; j <= n; j += i) h[j] = (h[j] - h[i]) % MOD;
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; j += i) ys[j].push_back(i);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1, a, b; i < n; ++i) scanf("%d%d", &a, &b), adde(a, b);
  dfs(1);
  dd(1);
  ans = (ans % MOD + MOD) % MOD;
  long long sb = n * (long long)(n - 1) / 2;
  sb %= MOD;
  sb = qp(sb, MOD - 2);
  ans = ans * sb % MOD;
  ans = (ans % MOD + MOD) % MOD;
  cout << ans << "\n";
}
