#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fRand(double fMin, double fMax) {
  double f = (double)rand() / RAND_MAX;
  return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
int n, a[100005], cnt[100005];
vector<int> d[100005];
int power(int x, int n) {
  if (n == 0) return 1;
  if (n & 1) return ((long long)x * power(x, n - 1)) % 1000000007;
  int p = power(x, n / 2);
  return ((long long)p * p) % 1000000007;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    scanf("%d", &a[i]);
    ++cnt[a[i]];
  }
  int m = *max_element(a + 1, a + n + 1);
  for (int x = (1); x <= (m); ++x) cnt[x] += cnt[x - 1];
  for (int x = (1); x <= (m); ++x)
    for (int i = (x); i <= (m); i += x) d[i].push_back(x);
  int ans = 0;
  for (int x = (1); x <= (m); ++x) {
    int k = (int)d[x].size(), q[k];
    for (int i = (0); i <= (k - 2); ++i)
      q[i] = cnt[d[x][i + 1] - 1] - cnt[d[x][i] - 1];
    q[k - 1] = cnt[m] - cnt[d[x][k - 1] - 1];
    int prod = 1;
    for (int i = (0); i <= (k - 2); ++i)
      prod = ((long long)prod * power(i + 1, q[i])) % 1000000007;
    prod = ((long long)prod *
            (power(k, q[k - 1]) - power(k - 1, q[k - 1]) + 1000000007)) %
           1000000007;
    ans = (ans + prod) % 1000000007;
  }
  printf("%d", ans);
  return 0;
}
