#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2,tune=native") #pragma GCC target("sse,sse2,abm,mmx") using namespace std; typedef long long lld; typedef pair<int, int> pii; typedef pair<lld, lld> pll; #define ff first #define dd second #define mp make_pair #define pb push_back #define sz size() #define For(i, s, a) for(int i = s; i < a; ++i) #define all(x) (x).begin(), (x).end() #define make_unique(x) (x).erase(unique(all(x)), (x).end()) lld c[5001], v[5001][5001]; const lld mod = 1e9 + 7; lld pot(lld a, lld b) { return !b ? 1 : (pot((a * a) % mod, b >> 1ll) * (b & 1ll ? a : 1)) % mod; } int main(void) { int n; scanf("%d", &n); For (i, 0, n) scanf("%lld", &c[i]); For (i, 0, n) For (j, i + 1, n) { lld xd = __gcd(c[i], c[j]); v[i][i] += xd; v[j][j] += xd; v[i][j] = v[j][i] = -xd; } const int lim = n - 1; For (i, 0, lim) { For (j, i + 1, lim) { if (!v[j][i]) continue; lld mn = ((mod - v[j][i]) * pot(v[i][i], mod - 2)) % mod; For (k, i, lim) v[j][k] += v[i][k] * mn; For (k, i, lim) v[j][k] = v[j][k] >= mod ? v[j][k] % mod : v[j][k]; } } lld wyn = 1; For (i, 0, lim) (wyn *= v[i][i]) %= mod; printf("%lld\n", (wyn + mod) % mod); }
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 | #include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2,tune=native") #pragma GCC target("sse,sse2,abm,mmx") using namespace std; typedef long long lld; typedef pair<int, int> pii; typedef pair<lld, lld> pll; #define ff first #define dd second #define mp make_pair #define pb push_back #define sz size() #define For(i, s, a) for(int i = s; i < a; ++i) #define all(x) (x).begin(), (x).end() #define make_unique(x) (x).erase(unique(all(x)), (x).end()) lld c[5001], v[5001][5001]; const lld mod = 1e9 + 7; lld pot(lld a, lld b) { return !b ? 1 : (pot((a * a) % mod, b >> 1ll) * (b & 1ll ? a : 1)) % mod; } int main(void) { int n; scanf("%d", &n); For (i, 0, n) scanf("%lld", &c[i]); For (i, 0, n) For (j, i + 1, n) { lld xd = __gcd(c[i], c[j]); v[i][i] += xd; v[j][j] += xd; v[i][j] = v[j][i] = -xd; } const int lim = n - 1; For (i, 0, lim) { For (j, i + 1, lim) { if (!v[j][i]) continue; lld mn = ((mod - v[j][i]) * pot(v[i][i], mod - 2)) % mod; For (k, i, lim) v[j][k] += v[i][k] * mn; For (k, i, lim) v[j][k] = v[j][k] >= mod ? v[j][k] % mod : v[j][k]; } } lld wyn = 1; For (i, 0, lim) (wyn *= v[i][i]) %= mod; printf("%lld\n", (wyn + mod) % mod); } |