正文
增加 16 行删除 15 行
460 行未改动全部展开461462463464465466467468469470471472473474149 行未改动全部展开62462562662762862963063163215 行未改动648649650651652653654655656657658659660661662663664665666667146 行未改动全部展开460 行未改动全部展开考虑 $p^{x - y - z}$ 怎么求。设 $g(n) = x$(上述 $p^{x - y - z}$ 中的 $x$)。再看看阶乘的式子$$n! = p^{\left\lfloor \frac{n}{p} \right\rfloor} \times \left(\left\lfloor \frac{n}{p} \right\rfloor\right)! \times \left(\prod_{i = 1, i \not\equiv 0 \pmod p}^{p^k} i\right)^{\left\lfloor \frac{n}{p^k} \right\rfloor} \left(\prod_{i = p^k \left\lfloor \frac{n}{p^k} \right\rfloor, i \not\equiv 0 \pmod p}^n i\right)$$所以我们可以得到以下递推式$$g(n) = \left\lfloor \frac{n}{p} \right\rfloor + g\left(\left\lfloor \frac{n}{p} \right\rfloor\right)149 行未改动全部展开```cpp#include <bits/stdc++.h>#define int long longusing namespace std;int n, a1, a2, m1, m2;int mul(int a, int b, int mod) {int ans = 0;while (b) {if (b & 1) ans = (ans + a) % mod;15 行未改动}signed main() {ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);cin >> n >> m1 >> a1;for (int i = 2; i <= n; i++) {cin >> m2 >> a2;exgcd(m1, m2);int d = __gcd(m1, m2);int k = m2 / d, qwq = (((a2 - a1) / d) % k + k) % k;x = (x % k + k) % k;x = mul(x, qwq, k);a1 += m1 * x;m1 *= k, a1 %= m1;}cout << a1;return 0;}```::::146 行未改动全部展开460 行未改动全部展开461462463464465466467468469470149 行未改动全部展开62062162262362462562662762815 行未改动644645646647648649650651652653654655656657658659660661662663664665666667668146 行未改动全部展开460 行未改动全部展开考虑 $p^{x - y - z}$ 怎么求。设 $g(n) = x$(上述 $p^{x - y - z}$ 中的 $x$)。我们查看原来的式子,可以发现,$n!$ 中显然有 $ \left\lfloor \frac{n}{p} \right\rfloor$ 个 $p$,然后还剩 $\left\lfloor \frac{n}{p} \right\rfloor !$ 的 $p$ 还没有求出,可以递归到 $g\left(\left\lfloor \frac{n}{p} \right\rfloor\right)$。所以我们可以得到以下递推式$$g(n) = \left\lfloor \frac{n}{p} \right\rfloor + g\left(\left\lfloor \frac{n}{p} \right\rfloor\right)149 行未改动全部展开```cpp#include <bits/stdc++.h>#define int long longusing namespace std;int n, A, B;int mul(int a, int b, int mod) {int ans = 0;while (b) {if (b & 1) ans = (ans + a) % mod;15 行未改动}signed main() {ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);cin >> n;A = 1, B = 0;for (int i = 1; i <= n; i++) {int a, b;cin >> a >> b;exgcd(A, a);int d = __gcd(A, a);int k = a / d;int qwq = (((B - b) / d) % k + k) % k;x = (x % k + k) % k;x = mul(x, qwq, k);B = B - A * x;A = A / d * a;B %= A;if (B < 0) B += A;}cout << B % A;return 0;}```::::146 行未改动全部展开