[BZOJ 2693] jzptab

[BZOJ 2693] jzptab

题目大意

给定 \(n\)\(m\),求 \[ \sum_{i = 1}^{n} \sum_{j = 1}^{m} lcm(i, \; j) \bmod 100,000,009 \] 多组询问。

\(1 \leqslant n, \; m \leqslant 10,000,000\)

题目链接

BZOJ 2693(权限题)

题解

BZOJ 2154

因为是权限题,所以我并没有提交,所以不知道能不能AC(代码是直接从BZOJ 2154改过来的),虽说应该可以。。。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cstdio>
#include <algorithm>
const int MAXN = 10000005;
const int MOD = 100000009;
long long f[MAXN];
int prime[MAXN], primeCnt;
bool notPrime[MAXN];
void linearShaker() {
notPrime[0] = notPrime[1] = true;
f[1] = 1;
for (int i = 2; i < MAXN; i++) {
if (!notPrime[i]) {
prime[++primeCnt] = i;
f[i] = (long long) i * (1 - i) % MOD;
}
for (int j = 1; j <= primeCnt && i * prime[j] < MAXN; j++) {
notPrime[i * prime[j]] = true;
if (i % prime[j] == 0) {
f[i * prime[j]] = f[i] * prime[j] % MOD;
break;
} else f[i * prime[j]] = f[i] * f[prime[j]] % MOD;
}
}
for (int i = 2; i < MAXN; i++) (f[i] += f[i - 1]) %= MOD;
}
long long pow(long long a, long long n) {
long long res = 1;
for (; n; n >>= 1, a = a * a % MOD) if (n & 1) res = res * a % MOD;
return res;
}
long long calc(int n, int m) {
if (n > m) std::swap(n, m);
long long res = 0;
for (int i = 1, last; i <= n; i = last + 1) {
last = std::min(n / (n / i), m / (m / i));
res += ((((long long) n / i) * ((long long) n / i + 1) / 2) % MOD)
* ((((long long) m / i) * ((long long) m / i + 1) / 2) % MOD) % MOD
* (f[last] - f[i - 1]) % MOD;
}
return (res % MOD + MOD) % MOD;
}
int main() {
linearShaker();
int T;
scanf("%d", &T);
while (T--) {
int n, m;
scanf("%d %d", &n, &m);
printf("%lld\n", calc(n, m));
}
return 0;
}