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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
#define dbg(x) " [" << #x << ": " << (x) << "] "
using namespace std;
template<typename A, typename B>
ostream& operator<<(ostream& out, const pair<A,B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& c) {
    out << "{";
    for(auto it = c.begin(); it != c.end(); it++) {
        if(it != c.begin()) out << ", ";
        out << *it;
    }
    return out << "}" << endl;
}
const int mod = 1e9 + 7;
vector<vector<long long>> v;
long long bp(long long a, long long b) {
    long long res = 1;
    while(b) {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int comp() {
    int n = v.size();
    long long det = 1;
    for(int i = 0; i < n; i++) {
        int p = i;
        for(int j = i + 1; j < n; j++) {
            if(v[j][i]) {
                p = j;
                break;
            }
        }
        if(!v[p][i]) {
            return 0;
        }
        if(i != p) {
            swap(v[i], v[p]);
            if(det) det = mod - det;
        }
        det = det * v[i][i] % mod;
        long long inv = bp(v[i][i], mod - 2);
        for(int j = i + 1; j < n; j++) {
            v[i][j] = v[i][j] * inv % mod;
        }
        for(int j = i + 1; j < n; j++) {
            if(v[j][i]) {
                for(int k = i + 1; k < n; k++) {
                    v[j][k] = (v[j][k] + mod - (v[j][i] * v[i][k] % mod)) % mod;
                }
            }
        }
    }
    return det;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> vv(n);
    for(int& i : vv) cin >> i;
    if(n == 1) {
        cout << 1 << endl;
        return 0;
    }
    v.assign(n - 1, vector<long long>(n - 1));
    for(int i = 0; i < n - 1; i++) {
        int s = 0;
        for(int j = 0; j < n; j++) {
            if(i != j) {
                int x = -gcd(vv[i], vv[j]);
                s -= x;
                if(j < n - 1) v[i][j] = mod + x;
            }
        }
        v[i][i] = s;
    }
    cout << comp() << endl;
    return 0;
}