結果
| 問題 | No.125 悪の花弁 |
| コンテスト | |
| ユーザー |
T1610
|
| 提出日時 | 2026-09-02 21:26:26 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 210 ms / 5,000 ms |
| + 145µs | |
| コード長 | 2,264 bytes |
| 記録 | |
| コンパイル時間 | 4,627 ms |
| コンパイル使用メモリ | 385,320 KB |
| 実行使用メモリ | 27,792 KB |
| 最終ジャッジ日時 | 2026-09-02 21:26:39 |
| 合計ジャッジ時間 | 7,291 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (ll i = (s); i < (ll)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (ll i = (ll)(s - 1); i >= (ll)(e); i--)
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <typename T, typename U>
bool chmax(T& a, const U& b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T, typename U>
bool chmin(T& a, const U& b) {
if (a <= b) return false;
a = b;
return true;
}
void yes_no(bool f, string yes = "Yes", string no = "No") {
cout << (f ? yes : no) << "\n";
}
template <class mint>
struct Comb {
vector<mint> fact;
vector<mint> ifact;
const int N;
Comb(int n) : fact(n + 1), ifact(n + 1), N(n + 1) { makeFact(); }
void makeFact() {
fact[0] = ifact[0] = 1LL;
for (int i = 1; i < N; i++) {
fact[i] = fact[i - 1] * (mint)i;
ifact[i] = fact[i].inv();
}
}
mint operator()(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (r > n / 2) r = n - r;
return fact[n] * ifact[n - r] * ifact[r];
}
};
void solve() {
int n;
cin >> n;
using mint = modint1000000007;
Comb<mint> c((int)2e6 + 10);
vl a(n);
rep(i, n) cin >> a[i];
if (n == 1) {
cout << 1 << '\n';
return;
}
ll sum = accumulate(all(a), 0LL);
ll g = a[0];
REP(i, 1, n)
g = __gcd(g, a[i]);
vl v;
for (ll i = 1; i * i <= g; ++i) {
if (g % i != 0) continue;
v.emplace_back(sum / i);
if (i * i != g) v.emplace_back(sum / (g / i));
}
sort(all(v));
mint ans = 0;
vector<mint> num((int)2e6 + 10);
rep(i, v.size()) {
ll x = v[i];
num[x] = c.fact[x];
rep(j, n) num[x] *= c.ifact[a[j] / (sum / x)];
rep(j, i) if (x % v[j] == 0) num[x] -= num[v[j]];
ans += num[x] / mint(x);
}
cout << ans.val() << "\n";
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
rep(ti, t) solve();
return 0;
}
T1610