标题
增加 1 行删除 1 行
1题解:P2260 [清华集训2012]模积和1题解:P2260 [清华集训2012] 模积和
正文
增加 6 行删除 103 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110原式就等于:$$\sum_{i = 1} ^ n \sum_{j = 1} ^ m (n \bmod i) \times (m \bmod j),i \not=j$$不妨设$n \leq m$。$$= \sum_{i = 1} ^ n (n \bmod i) \times \sum_{j = 1} ^ m (m \bmod j) - \sum_{i = 1} ^ n (n \bmod i) \times (m \bmod i)$$$$= \sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i)\times \sum_{j = 1} ^ m (m - \left \lfloor \frac{m}{j} \right \rfloor \times j)-\sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i) (m - \left \lfloor \frac{n}{j} \right \rfloor \times j)$$$$= \sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i)\times \sum_{j = 1} ^ m (m - \left \lfloor \frac{m}{j} \right \rfloor \times j)-\sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i) (m - \left \lfloor \frac{m}{i} \right \rfloor \times i)$$$$= \sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i)\times \sum_{j = 1} ^ m (m - \left \lfloor \frac{m}{j} \right \rfloor \times j)-\sum_{i = 1} ^ n (nm - n \times i \times \left \lfloor \frac{m}{i} \right \rfloor - m \times i \times \left \lfloor \frac{n}{i} \right \rfloor + i ^ 2 \times \left \lfloor \frac{n}{i} \right \rfloor \times \left \lfloor \frac{m}{i} \right \rfloor)$$显然对这$3$坨数论分块就可以了```cpp#include<bits/stdc++.h>xian'ranusing zheng'chunamespace std;#define int long longconst int mod = 19940417;int fastpow(int a, int b){int res = 1;while (b) {if (b & 1) {res = (res * a) % mod;}a = (a * a) % mod;b >>= 1;}return res;}int calc(int x){return (x * (x + 1) / 2) % mod;}int calcc(int x){return (((x * (x + 1)) % mod * (2 * x + 1)) % mod * 3323403) % mod;}signed main(){int n, m;cin >> n >> m;if (n > m) {swap(n, m);}int ans1 = 0;for (int l = 1; l <= n; ) {int r = n / (n / l);int d = n / l;ans1 = (ans1 + mod + ((calc(r) - calc(l - 1)) * d) % mod) % mod;l = r + 1;}ans1 = (n * n % mod + mod - ans1) % mod;int ans2 = 0;for (int l = 1; l <= m; ) {int r = m / (m / l);int d = m / l;ans2 = (ans2 + mod + ((calc(r) - calc(l - 1)) * d) % mod) % mod;l = r + 1;}ans2 = (m * m % mod + mod - ans2) % mod;int ans = ans1 * ans2 % mod;int ans3 = 0;for (int l = 1; l <= n; ) {int r = min(n / (n / l), m / (m / l));int d1 = n / l;int d2 = m / l;int b = ((calc(r) - calc(l - 1) + mod) % mod * (d1 * m % mod + d2 * n % mod)) % mod;int c = (((calcc(r) - calcc(l - 1) + mod) % mod * d1) % mod * d2) % mod;ans3 = (ans3 + (((r - l + 1) * n) % mod * m) % mod + mod - b + c) % mod;l = r + 1;}ans = (ans - ans3 + mod) % mod;cout << ans;return 0;}```12345678910111213不妨设$n \leq m$。那原式:$$ = \sum_{i = 1} ^ n (n \bmod i) \times \sum_{j = 1} ^ m (m \bmod j) - \sum_{i = 1} ^ n (n \bmod i) \times (m \bmod i) $$$$ = \sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i)\times \sum_{j = 1} ^ m (m - \left \lfloor \frac{m}{j} \right \rfloor \times j)-\sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i) (m - \left \lfloor \frac{m}{i} \right \rfloor \times i)$$$$= \sum_{i = 1} ^ n (n - \left \lfloor \frac{n}{i} \right \rfloor \times i)\times \sum_{j = 1} ^ m (m - \left \lfloor \frac{m}{j} \right \rfloor \times j)-\sum_{i = 1} ^ n (nm - n \times i \times \left \lfloor \frac{m}{i} \right \rfloor - m \times i \times \left \lfloor \frac{n}{i} \right \rfloor + i ^ 2 \times \left \lfloor \frac{n}{i} \right \rfloor \times \left \lfloor \frac{m}{i} \right \rfloor)$$显然对这$3$坨数论分块就可以了