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
87
88
89
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<int,long long> PIL;
const int mod = 1e9+7;

int nwd(int a, int b){
    if(b == 0) return a;
    return nwd(b, a%b);
}
long long pot(long long a, int x){
    if(x == 0) return 1;
    if(x&1) return pot(a, x-1)*a%mod;
    long long tmp = pot(a, x/2);
    return tmp*tmp%mod;
}

#define mp make_pair
#define pb push_back
#define x first
#define y second
#define rep(i,b,e) for(int i=(b); i<(e); i++)
#define each(a,x) for(auto& a : (x))
#define all(x) (x).begin(),(x).end()
#define sz(x) int((x).size())

using Row = vector<long long>;
using Matrix = vector<Row>;

// copied for jagiellonian algolib
int echelon(Matrix& A, int& sign) { // O(nˆ3)
int rank = 0;
sign = 1;
rep(c, 0, sz(A[0])) {
if (rank >= sz(A)) break;
rep(i, rank+1, sz(A)) if (A[i][c]) {
swap(A[i], A[rank]);
sign *= -1;
break;
} // f98a
if (A[rank][c]) {
rep(i, rank+1, sz(A)) {
long long mult = (A[i][c] * pot(A[rank][c], mod-2))%mod;
rep(j, 0, sz(A[0]))
A[i][j] = (A[i][j]-A[rank][j]*mult)%mod;
} // f519
rank++;
} // 4cd8
//cout<<"c "<<c<<endl;
} // 36e9
return rank;
}

long long det(Matrix A) {
int s; echelon(A, s);
long long ret = s;
rep(i, 0, sz(A)) ret = (ret*A[i][i])%mod;
if(ret < 0) ret += mod;
return ret;
} // b252

int arr[5005];

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    Matrix A(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++){
        A[i].push_back(nwd(arr[i], arr[j]));
    }
    if(n == 1){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        int sum = 0;
        for(int j=0;j<n;j++){
            sum += A[i][j];
            A[i][j] = -A[i][j];
        }
        A[i][i] += sum;
    }
    for(int i=0;i<n;i++) A[i].pop_back();
    A.pop_back();

    cout<<det(A)<<endl;
}