MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / main

Function main

Math/Thomas Algorithm.cpp:67–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66int a[N];
67int32_t main() {
68 ios_base::sync_with_stdio(0);
69 cin.tie(0);
70 int n; cin >> n;
71 mint m = 0;
72 for (int i = 0; i < n; i++) cin >> a[i], m += a[i];
73 vector<vector<mint>> mat(m.value + 1);
74 for (int i = 0; i <= m.value; i++) {
75 vector<mint> v(4, 0);
76 if (i) v[0] = mint(i) / m;
77 v[1] = (m - i) * (n - 2) / m / (n - 1) - 1;
78 if (i + 1 <= m.value) v[2] = (m - i) / m / (n - 1);
79 v[3] = mint(-i) / m;
80 mat[i] = v;
81 }
82 vector<mint> f = Thomas(mat);
83 mint ans = 0;
84 for (int i = 0; i < n; i++) ans += f[a[i]];
85 ans -= (n - 1) * f[0] + f[m.value];
86 cout << ans << '\n';
87 return 0;
88}
89// https://codeforces.com/contest/1349/problem/D

Callers

nothing calls this directly

Calls 1

ThomasFunction · 0.70

Tested by

no test coverage detected