結果

問題 No.125 悪の花弁
ユーザー sugim48sugim48
提出日時 2015-01-11 23:57:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 654 ms / 5,000 ms
コード長 1,785 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 79,320 KB
実行使用メモリ 23,196 KB
最終ジャッジ日時 2023-09-04 04:30:23
合計ジャッジ時間 5,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 551 ms
21,332 KB
testcase_01 AC 639 ms
21,968 KB
testcase_02 AC 648 ms
23,048 KB
testcase_03 AC 654 ms
23,196 KB
testcase_04 AC 618 ms
22,640 KB
testcase_05 AC 617 ms
22,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

ll gcd(ll a, ll b) {
	if (b == 0) return abs(a);
	else return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = (a >= 0) ? 1 : -1;
		y = 0;
		return abs(a);
	}
	else {
		ll res = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
		return res;
	}
}

ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

int main() {
	vector<ll> f(1000001), fi(1000001);
	f[0] = fi[0] = 1;
	for (int i = 1; i <= 1000000; i++) {
		f[i] = (f[i - 1] * i) % MOD;
		fi[i] = mod_inverse(f[i], MOD);
	}
	int K; cin >> K;
	int n = 0;
	vector<int> C(K);
	for (int i = 0; i < K; i++) {
		cin >> C[i];
		n += C[i];
	}
	vector<int> a(n + 1);
	for (int j = 0; j < n; j++) {
		int k = gcd(n, j);
		a[k]++;
	}
	ll sum = 0;
	for (int k = 1; k <= n; k++) {
		if (n % k) continue;
		int j = n / k;
		bool ok = true;
		for (int i = 0; i < K; i++)
			if (C[i] % j) ok = false;
		if (!ok) continue;
		ll prod = f[k];
		for (int i = 0; i < K; i++) {
			int c = C[i] / j;
			prod = (prod * fi[c]) % MOD;
		}
		sum = (sum + a[k] * prod) % MOD;
	}
	sum = (sum * mod_inverse(n, MOD)) % MOD;
	cout << sum << endl;
}
0