#include <bits/stdc++.h>
using namespace std;
int a[100005];
inline int lowbit(int x) { return x & -x; }
void update(int x) {
  while (x <= 100000) {
    a[x] += 1;
    x += lowbit(x);
  }
}
int query(int x) {
  int ret = 0;
  while (x > 0) {
    ret += a[x];
    x -= lowbit(x);
  }
  return ret;
}
long long Pow(long long x, int y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % 1000000007;
    x = x * x % 1000000007;
    y >>= 1;
  }
  return ret;
}
int main() {
  int n, i, j;
  while (scanf("%d", &n) != EOF) {
    int mx = 0, x;
    memset(a, 0, sizeof(a));
    for (i = 1; i <= n; i++) {
      scanf("%d", &x);
      update(x);
      mx = max(mx, x);
    }
    long long ans = 0;
    for (i = 1; i <= mx; i++) {
      vector<int> v;
      for (j = 1; j * j <= i; j++) {
        if (i % j == 0) {
          v.push_back(j);
          if (j != i / j) v.push_back(i / j);
        }
      }
      sort(v.begin(), v.end());
      int pre, now = 0;
      long long ret = 1;
      for (j = 1; j < v.size(); j++) {
        pre = now;
        now = query(v[j] - 1);
        if (now == pre) continue;
        ret = ret * Pow(j, now - pre) % 1000000007;
      }
      long long tmp =
          Pow((long long)j, n - now) - Pow((long long)(j - 1), n - now);
      ret = ret * tmp % 1000000007;
      ans = (ans + ret) % 1000000007;
    }
    printf("%I64d\n",
           ((ans + 1000000007) % 1000000007 + 1000000007 % 1000000007));
  }
  return 0;
}
