#include <bits/stdc++.h>
using namespace std;
int n, a[200000];
const long long Mod = 1000000007;
long long factor[20000], tot, f[200000];
int cnt[200000];
long long len[20000], ltot;
void resolve(int x) {
  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      factor[tot++] = i;
      if (i * i != x) factor[tot++] = x / i;
    }
  }
}
int find(int x) {
  int l = 0, r = n - 1;
  while (l <= r) {
    int mid = l + r >> 1;
    if (a[mid] < x)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return l;
}
long long fastmul(long long a, long long p) {
  a %= Mod;
  long long ret = 1;
  while (p) {
    if (p & 1) ret *= a, ret %= Mod;
    a *= a, a %= Mod;
    p /= 2;
  }
  return ret;
}
int main() {
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i), cnt[a[i]]++;
  for (int i = 100000; i >= 0; --i) cnt[i] += cnt[i + 1];
  sort(a, a + n);
  for (int Max = 1; Max <= 100000; ++Max) {
    if (cnt[Max] == 0) break;
    ltot = tot = 0;
    resolve(Max);
    for (int i = 0; i < tot; ++i) {
      len[ltot++] = n - find(factor[i]);
    }
    sort(len, len + ltot);
    long long fac = ltot;
    long long delta = 1, bef = 0;
    for (int i = 0; i < ltot; ++i, fac--) {
      if (i == 0)
        delta *= (fastmul(fac, len[i] - bef) - fastmul(fac - 1, len[i] - bef));
      else
        delta *= fastmul(fac, len[i] - bef);
      bef = len[i];
      delta %= Mod;
    }
    f[Max] = delta;
  }
  for (int i = 1; i <= 100000; ++i) {
    if (f[i] == 0) break;
    ans += f[i];
    ans %= Mod;
  }
  if (ans < 0) ans %= Mod, ans += Mod;
  printf("%I64d\n", ans % Mod);
  return 0;
}
