結果
| 問題 | No.125 悪の花弁 |
| コンテスト | |
| ユーザー |
Yang33
|
| 提出日時 | 2018-05-01 19:10:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 189 ms / 5,000 ms |
| コード長 | 3,351 bytes |
| コンパイル時間 | 2,023 ms |
| コンパイル使用メモリ | 185,388 KB |
| 実行使用メモリ | 27,136 KB |
| 最終ジャッジ日時 | 2024-06-28 00:12:29 |
| 合計ジャッジ時間 | 3,145 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#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 ----- */
/* ------問題------
-----問題ここまで----- */
/* -----解説等-----
蟻本読んでた
----解説ここまで---- */
map<int, int>MapMoebius(int n) {
map<int, int>res;
vector<int>primes;
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<long long> 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);
map<int, int>moebious = 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;
}
Yang33