#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228228;
vector<long long> a[N];
long long i, j, n, m, e, b[N], t, dp[N], k, o;
long long get(int l, int r) {
  if (!l)
    return dp[r];
  else
    return dp[r] - dp[l - 1];
}
long long Pow(long long a, long long b) {
  if (!b) return 1;
  if (b % 2 == 0) {
    long long d = Pow(a, b / 2);
    return d * d % 1000000007;
  } else
    return Pow(a, b - 1) * a % 1000000007;
}
int main() {
  cin >> n;
  for (i = 1; i < N; i++)
    for (j = i; j < N; j += i) a[j].push_back(i);
  for (i = 0; i < n; i++) scanf("%d", &b[i]), dp[b[i]]++, t = max(t, b[i]);
  for (i = 1; i <= t; i++) dp[i] += dp[i - 1];
  for (i = 1; i <= t; i++) {
    e = 1;
    for (j = 0; j < a[i].size() - 1; j++)
      e *= Pow(j + 1, get(a[i][j], a[i][j + 1] - 1)), e %= 1000000007;
    e *= (Pow(j + 1, get(a[i][j], t)) - Pow(j, get(a[i][j], t))),
        e %= 1000000007, e += 1000000007, e %= 1000000007;
    o += e, o %= 1000000007;
  }
  cout << o << "\n";
}
