#include using namespace std; using VS = vector; using LL = long long; using VI = vector; using VVI = vector; using PII = pair; using PLL = pair; using VL = vector; using VVL = vector; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define SORT(c) sort(ALL((c))) #define RSORT(c) sort(RALL((c))) #define UNIQ(c) (c).erase(unique(ALL((c))), end((c))) #define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++) #define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--) #define debug(x) cerr << #x << ": " << x << endl const int INF = 1e9; const LL LINF = 1e16; const LL MOD = 1000000007; const double PI = acos(-1.0); int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 }; /* ----- 2018/05/01 Problem: yukicoder 125 / Link: http://yukicoder.me/problems/no/125 ----- */ /* ------問題------ -----問題ここまで----- */ /* -----解説等----- 蟻本読んでた ----解説ここまで---- */ mapMapMoebius(int n) { mapres; vectorprimes; for (int i = 2; i*i <= n; i++) { if (n%i == 0) { primes.push_back(i); while (n%i == 0)n /= i; } } if (n != 1)primes.push_back(n); int m = (int)primes.size(); for (int i = 0; i < (1 << m); i++) {//logn個も無いので余裕? int mu = 1, d = 1; for (int j = 0; j < m; j++) { if (i >> j & 1) { mu *= -1; d *= primes[j]; } } res[d] = mu; } return res; } long long modpow(long long a, long long b) { if (b == 0) return 1; return modpow(a * a % MOD, b / 2) * (b & 1 ? a : 1) % MOD; } long long modinv(long long a) { return modpow(a, MOD - 2); } vector fact, inv_fact; void init_fact(int n) { fact.resize(n); fact[0] = 1; for (int i = 1; i < n; i++) { fact[i] = i * fact[i - 1] % MOD; } inv_fact.resize(n); inv_fact[n - 1] = modinv(fact[n - 1]); for (int i = n - 2; i >= 0; i--) { inv_fact[i] = (i + 1) * inv_fact[i + 1] % MOD; } } VI getdivisor(int n) { VI res; for (int i = 1; i*i <= n; i++) { if (n%i == 0) { res.push_back(i); if (n / i != i)res.push_back(n / i); } } SORT(res); return res; } LL N; LL ans = 0LL; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int K; cin >> K; VI c(K); FOR(i, 0, K) { cin >> c[i]; } N = accumulate(ALL(c), 0); mapmoebious = MapMoebius(N); init_fact(N + 1); VL unit_c(N + 1, 0); FOR(i, 1, N + 1) { if (N%i == 0) { int ok = 1; int d = N / i;//groupのサイズi,グループの個数d FOR(j, 0, K) { if (c[j] % d)ok = 0; } if (!ok)continue; LL comb = fact[i]; FOR(j, 0, K) { comb *= inv_fact[c[j] / d]; comb %= MOD; } unit_c[i] = comb; } } FOR(i, 1, N + 1) { if (N%i == 0) { int ok = 1; int d = N / i;//groupのサイズi,グループの個数d FOR(j, 0, K) { if (c[j] % d)ok = 0; } if (!ok)continue; VI divs = getdivisor(i); LL ret = 0; for (int div : divs) { ret += (unit_c[div] * moebious[i / div]) % MOD; (ret += MOD) %= MOD; } ans += ret*(d); ans %= MOD; } } ans *= modinv(N); // ans/=N ans %= MOD; cout << ans << "\n"; return 0; }