#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
int cnt[1000005];
long long pow(int x, int p) {
  if (p == 1) return x;
  if (p == 0) return 1;
  long long tmp = pow(x, p / 2);
  tmp = tmp * tmp % 1000000007;
  if (p & 1) tmp = tmp * x % 1000000007;
  return tmp;
}
int a[100005];
vector<int> v[100005];
int main(void) {
  int n;
  scanf("%d", &n);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    mx = max(mx, a[i]);
  }
  for (int i = 1; i <= 100000; i++) cnt[i] += cnt[i - 1];
  for (int i = 1; i <= 100000; i++)
    for (int j = i; j <= 100000; j += i) v[j].push_back(i);
  long long ans = 0;
  for (int i = 1; i <= mx; i++) {
    long long ret = 1;
    int sz = v[i].size();
    for (int j = 1; j < sz; j++) {
      int tmp = cnt[v[i][j] - 1] - cnt[v[i][j - 1] - 1];
      ret *= pow(j, tmp);
      ret %= 1000000007;
    }
    long long tmp = ret;
    ret *= pow(sz, cnt[mx] - cnt[i - 1]);
    ret %= 1000000007;
    ret -= tmp * pow(sz - 1, cnt[mx] - cnt[i - 1]);
    ret = (ret % 1000000007 + 1000000007) % 1000000007;
    ans += ret;
    ans %= 1000000007;
  }
  printf("%I64d\n", ans);
}
