結果
問題 | No.125 悪の花弁 |
ユーザー |
![]() |
提出日時 | 2015-01-12 16:57:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 571 ms / 5,000 ms |
コード長 | 2,273 bytes |
コンパイル時間 | 998 ms |
コンパイル使用メモリ | 81,752 KB |
実行使用メモリ | 27,344 KB |
最終ジャッジ日時 | 2024-06-22 04:33:57 |
合計ジャッジ時間 | 5,011 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:77:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 77 | scanf("%d", C+i); | ~~~~~^~~~~~~~~~~
ソースコード
#include <sstream>#include <string>#include <vector>#include <map>#include <algorithm>#include <iostream>#include <utility>#include <set>#include <cctype>#include <queue>#include <stack>#include <cstdio>#include <cstdlib>#include <cmath>#define INF 1000000000using namespace std;typedef long long ll;const int MAXK = 100100;const int MAXT = 1000010;const ll MOD = 1000000007;int K;int C[MAXK];ll fact[MAXT], inv[MAXT], normalinv[MAXT];ll modpow(ll a, ll n) {if (n == 0) return 1;if (n == 1) return a;if (n % 2 == 0) {ll tmp = modpow(a, n/2);return (tmp * tmp) % MOD;} else {ll tmp = modpow(a, n-1);return (tmp * a) % MOD;}}// extgcdll extgcd(ll a, ll b, ll& x, ll& y) {ll d = a;if (b != 0) {d = extgcd(b, a % b, y, x);y -= (a / b) * x;} else {x = 1; y = 0;}return d;}// mod_inversell mod_inverse(ll a, ll m = MOD) {ll x, y;extgcd(a, m, x, y);return (m+x%m) % m;}void init() {fact[0] = inv[0] = 1;for (ll i = 1; i < MAXT; i++) {fact[i] = (fact[i-1] * i) % MOD;inv[i] = mod_inverse(fact[i]);}for (ll i = 1; i < MAXT; i++) {normalinv[i] = mod_inverse(i);}}int main(void) {init();//for (int i = 0; i < 10; i++) {// cout << fact[i] << " " << inv[i] << endl;//}cin >> K;int g = 0, T = 0;for (int i = 0; i < K; i++) {scanf("%d", C+i);g = __gcd(g, C[i]);T += C[i];}vector<int> V;for (int i = 1; i * i <= g; i++) {if (g % i == 0) {V.push_back(T/i);if (i*i != g) V.push_back(T/(g/i));}}sort(V.begin(), V.end());ll ans = 0;vector<ll> P(V.size());for (int i = 0; i < V.size(); i++) {ll G = T / V[i];P[i] = fact[V[i]];for (int j = 0; j < K; j++) {P[i] = (P[i] * inv[C[j]/G]) % MOD;}for (int j = 0; j < V.size(); j++) {if (j >= i) break;if (V[i] % V[j] == 0) P[i] = (P[i]-P[j]) % MOD;if (P[i] < 0) P[i] += MOD;}ans = (ans + P[i] * normalinv[V[i]]) % MOD;}cout << ans << endl;return 0;}