結果
| 問題 |
No.125 悪の花弁
|
| コンテスト | |
| ユーザー |
assy1028
|
| 提出日時 | 2016-12-19 17:03:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,536 bytes |
| コンパイル時間 | 803 ms |
| コンパイル使用メモリ | 101,408 KB |
| 実行使用メモリ | 19,660 KB |
| 最終ジャッジ日時 | 2024-12-14 08:59:44 |
| 合計ジャッジ時間 | 4,540 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 6 |
ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;
#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int k;
ll c[100100];
ll sum = 0;
ll d[1010];
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
ll mod_inverse(ll x) {
return mod_pow(x, mod-2);
}
const int max_n = 1000100;
ll fact[max_n];
ll fact_inv[max_n];
void calc_fact() {
fact[0] = 1;
for (ll i = 1; i < max_n; i++)
fact[i] = (fact[i-1] * i) % mod;
fact_inv[max_n-1] = mod_inverse(fact[max_n-1]);
for (ll i = max_n-2; i >= 0; i--)
fact_inv[i] = (fact_inv[i+1] * (i+1)) % mod;
}
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a%b);
}
ll solve() {
for (int i = 0; i < k; i++) sum += c[i];
calc_fact();
for (int i = 1; i * i <= sum; i++) {
if (sum % i == 0) {
d[i] = fact[sum/i];
for (int j = 0; j < k; j++) {
if (c[j] % i) {
d[i] = 0;
break;
} else {
d[i] = d[i] * fact_inv[c[j]/i] % mod;
}
}
}
}
swap(d[0], d[1]);
ll res = d[0];
for (int i = 1; i < sum; i++) {
res = (res + d[gcd(sum, i)]) % mod;
}
return res * mod_inverse(sum) % mod;
}
void input() {
cin >> k;
for (int i = 0; i < k; i++) cin >> c[i];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
input();
cout << solve() << endl;
}
assy1028