1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
using u32 = unsigned;
using u64 = unsigned long long;
constexpr int N = 2010;
constexpr u32 mod = 1e9 + 7;
int n, v[N];
u32 a[N][N];
inline int fpw(int a, int b) {
	int ans = 1;
	for(; b; b >>= 1, a = 1ll * a * a % mod) if(b & 1) ans = 1ll * ans * a % mod;
	return ans;
}
int det() {
	int ans = 1;
	for(int i = 1; i <= n; i ++) {
		int p = -1;
		for(int j = i; j <= n; j ++) if(a[j][i]) p = j;
		if(p != i) {
			swap(a[p], a[i]);
			ans = mod - ans;
		}
		int inv = fpw(a[i][i], mod - 2);
		for(int j = i + 1; j <= n; j ++) {
			const u64 d = mod - 1ll * a[j][i] * inv % mod;
			for(int k = i; k <= n; k ++) {
				a[j][k] = (a[j][k] + d * a[i][k]) % mod;
			}
		}
		ans = 1ll * ans * a[i][i] % mod;
	}
	return ans;
}
int main() {
	// freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n; 
	for(int i = 1; i <= n; i ++) cin >> v[i];
	for(int i = 1; i <= n; i ++) {
		for(int j = i + 1; j <= n; j ++) {
			int w = __gcd(v[i], v[j]);
			a[i][j] = a[j][i] = mod - w;
			a[i][i] = (a[i][i] + w) % mod;
			a[j][j] = (a[j][j] + w) % mod;
		}
	}
	n --;
	cout << det() << '\n';
	return 0;
}