// Marcin Knapik #pragma GCC optimize ("O3") #include<bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; i++) #define f first #define s second #define pb push_back #define all(s) s.begin(), s.end() #define sz(s) (int)s.size() using ll = long long; using vi = vector<int>; using vvi = vector<vi>; template <class T>ostream &operator<<(ostream &os, vector<T> &vec){for (T &el : vec){os << el << ' ';}return os;} template <class T>istream &operator>>(istream &is, vector<T> &vec) {for (T &el : vec){is >> el;}return is;} template <class T, class G> ostream &operator<<(ostream &os, pair<T, G> para) { os << para.f << ' ' << para.s; return os;} using ll = long long; using vi = vector<int>; using ii = pair<int, int>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using vvpll = vector<vpll>; using vii = vector<ii>; using mp = map<vector<string>, long double>; using ld = long double; #define rep(i,a,b) for(int i = a; i < b; i++) const ll mod = 1e9 + 7; ll det(vector<vector<ll>>& a) { int n = sz(a); ll ans = 1; rep(i,0,n) { rep(j,i+1,n) { while (a[j][i] != 0) { // gcd step ll t = a[i][i] / a[j][i]; if (t) rep(k,i,n) a[i][k] = (a[i][k] - a[j][k] * t) % mod; swap(a[i], a[j]); ans *= -1; } } ans = ans * a[i][i] % mod; if (!ans) return 0; } return (ans + mod) % mod; } void solve(){ int n; cin >> n; vi tab(n); for(int i = 0; i < n; i++) cin >> tab[i]; vector<vector<ll>> pom(n - 1, vll(n - 1)); for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ int GCD = __gcd(tab[i], tab[j]); if(i < n - 1) pom[i][i] += GCD; if(j < n - 1) pom[j][j] += GCD; if(i < n - 1 and j < n - 1){ pom[i][j] -= GCD; pom[j][i] -= GCD; } } } cout << det(pom) << '\n'; } int main () { ios::sync_with_stdio(0); cin.tie(0); int tests = 1; // cin >> tests; for (int test = 1; test <= tests; test++) { solve(); } return 0; }
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 90 91 92 93 94 | // Marcin Knapik #pragma GCC optimize ("O3") #include<bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; i++) #define f first #define s second #define pb push_back #define all(s) s.begin(), s.end() #define sz(s) (int)s.size() using ll = long long; using vi = vector<int>; using vvi = vector<vi>; template <class T>ostream &operator<<(ostream &os, vector<T> &vec){for (T &el : vec){os << el << ' ';}return os;} template <class T>istream &operator>>(istream &is, vector<T> &vec) {for (T &el : vec){is >> el;}return is;} template <class T, class G> ostream &operator<<(ostream &os, pair<T, G> para) { os << para.f << ' ' << para.s; return os;} using ll = long long; using vi = vector<int>; using ii = pair<int, int>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using vvpll = vector<vpll>; using vii = vector<ii>; using mp = map<vector<string>, long double>; using ld = long double; #define rep(i,a,b) for(int i = a; i < b; i++) const ll mod = 1e9 + 7; ll det(vector<vector<ll>>& a) { int n = sz(a); ll ans = 1; rep(i,0,n) { rep(j,i+1,n) { while (a[j][i] != 0) { // gcd step ll t = a[i][i] / a[j][i]; if (t) rep(k,i,n) a[i][k] = (a[i][k] - a[j][k] * t) % mod; swap(a[i], a[j]); ans *= -1; } } ans = ans * a[i][i] % mod; if (!ans) return 0; } return (ans + mod) % mod; } void solve(){ int n; cin >> n; vi tab(n); for(int i = 0; i < n; i++) cin >> tab[i]; vector<vector<ll>> pom(n - 1, vll(n - 1)); for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ int GCD = __gcd(tab[i], tab[j]); if(i < n - 1) pom[i][i] += GCD; if(j < n - 1) pom[j][j] += GCD; if(i < n - 1 and j < n - 1){ pom[i][j] -= GCD; pom[j][i] -= GCD; } } } cout << det(pom) << '\n'; } int main () { ios::sync_with_stdio(0); cin.tie(0); int tests = 1; // cin >> tests; for (int test = 1; test <= tests; test++) { solve(); } return 0; } |