#include <bits/stdc++.h>
int n, m, l, x, oo = 1000000007, c[100005], a[100005], b[100005];
long long res = 1, ans;
long long Exp(long long x, long long y) {
  long long res = 1;
  for (; y; y >>= 1, x = x * x % oo)
    if (y & 1) res = res * x % oo;
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &x), c[x]++;
  for (int i = 100005 - 5; i; i--) c[i - 1] += c[i];
  for (int i = 1; c[i]; i++) {
    m = l = 0, res = 1;
    for (int j = 1; j * j <= i; j++)
      if (i % j == 0) {
        a[m++] = j;
        if (j * j - i) b[l++] = i / j;
      }
    while (l--) a[m++] = b[l];
    for (int j = 1; j < m; j++) res = res * Exp(j, c[a[j - 1]] - c[a[j]]) % oo;
    ans = (ans + res * (Exp(m, c[i]) - Exp(m - 1, c[i]))) % oo;
  }
  printf("%d\n", (ans + oo) % oo);
  return 0;
}
