using
System;
using
System.Collections.Generic;
class
MainClass {
const
int
MOD = 1000000007;
const
int
N = 100005;
static
List<
int
> BIT =
new
List<
int
>(
new
int
[N]);
static
int
Power(
int
x,
int
y) {
if
(x == 0)
return
0;
int
ans = 1;
while
(y > 0) {
if
((y & 1) == 1)
ans = (
int
)((1L * ans * x) % MOD);
x = (
int
)((1L * x * x) % MOD);
y >>= 1;
}
return
ans;
}
static
void
UpdateBIT(
int
idx,
int
val) {
if
(idx <= 0)
return
;
while
(idx < N) {
BIT[idx] += val;
idx += idx & -idx;
}
}
static
int
QueryBIT(
int
idx) {
int
ans = 0;
while
(idx > 0) {
ans += BIT[idx];
idx -= idx & -idx;
}
return
ans;
}
static
int
NumWays(
int
[] arr,
int
n) {
int
mx = 0;
for
(
int
i = 0; i < n; i++) {
UpdateBIT(arr[i], 1);
mx = Math.Max(mx, arr[i]);
}
int
ans = 1;
for
(
int
i = 2; i <= mx; i++) {
List<
int
> factors =
new
List<
int
>();
for
(
int
j = 1; j * j <= i; j++) {
if
(i % j == 0) {
factors.Add(j);
if
(i / j != j)
factors.Add(i / j);
}
}
factors.Sort((a, b) => b.CompareTo(a));
int
cnt = 1;
int
prev = 0;
for
(
int
j = 0; j < factors.Count; j++) {
int
remFactors = factors.Count - j;
int
indexes = n - QueryBIT(factors[j] - 1);
cnt = (
int
)(
(1L * cnt * Power(remFactors, indexes - prev)) % MOD);
prev = Math.Max(prev, indexes);
}
factors.RemoveAt(0);
int
toSubtract = 1;
prev = 0;
for
(
int
j = 0; j < factors.Count; j++) {
int
remFactors = factors.Count - j;
int
indexes = n - QueryBIT(factors[j] - 1);
toSubtract = (
int
)(
(1L * toSubtract * Power(remFactors, indexes - prev)) % MOD);
prev = Math.Max(prev, indexes);
}
ans = (
int
)((1L * ans + cnt - toSubtract + MOD) % MOD);
}
return
ans;
}
public
static
void
Main(
string
[] args) {
int
[] arr = { 6, 3 };
int
n = arr.Length;
int
ans = NumWays(arr, n);
Console.WriteLine(ans);
}
}