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
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long n, tab[5007], wynik, res = 1;

long long gcd(long long a, long long b) {
    long long shift;
    if (!a) return b;
    if (!b) return a;
    shift = __builtin_ctz(a | b);
    a >>= __builtin_ctz(a);
    do {
        b >>= __builtin_ctz(b);
        if (a > b) {
            unsigned int x = b;
            b = a;
            a = x;
        }  
        b = b - a;
    } while (b != 0);
    return a << shift;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> tab[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            long long liczba1 = tab[i], liczba2 = tab[j];  
            wynik += gcd(liczba1, liczba2);
        }
    }
    wynik -= n-1;
    for (int i = 2; i <= wynik; i++) {
        res *= i;
        res %= mod;
    }
    cout << res << "\n";
}