标签:
速度居然#2...目测是因为我没用long long..
求∑ lcm(i, j) (1 <= i <= n, 1 <= j <= m)
化简之后就只须求f(x) = x∑u(d)*d (d | x) 然后就是分块了...
-------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 10000009;
const int MOD = 100000009;
bool check[maxn];
int f[maxn], prime[maxn], N = 0;
void init() {
memset(check, false, sizeof check);
f[0] = 0; f[1] = 1;
for(int i = 2; i < maxn; i++) {
if(!check[i]) {
prime[N++] = i;
f[i] = ll(i) * (1 - i) % MOD;
}
for(int j = 0; j < N && ll(i) * prime[j] < maxn; j++) {
check[i * prime[j]] = true;
if(i % prime[j])
f[i * prime[j]] = ll(f[i]) * f[prime[j]] % MOD;
else {
f[i * prime[j]] = ll(prime[j]) * f[i] % MOD;
break;
}
}
}
for(int i = 1; i < maxn; i++)
f[i] = (f[i] + f[i - 1]) % MOD;
}
inline int sum(int a, int b) {
return (ll(a) * (a + 1) / 2 % MOD) * (ll(b) * (b + 1) / 2 % MOD) % MOD;
}
void work(int x, int y) {
if(x > y) swap(x, y);
int ans = 0;
for(int L = 1; L <= x; L++) {
int R = min(x / (x / L), y / (y / L));
(ans += 1ll * sum(x / L, y / L) * (f[R] - f[L - 1]) % MOD) %= MOD;
L = R;
}
printf("%d\n", (ans + MOD) % MOD);
}
int main() {
init();
int t; scanf("%d", &t);
while(t--) {
int x, y;
scanf("%d%d", &x, &y);
work(x, y);
}
return 0;
}
-------------------------------------------------------------------
2693: jzptab
Time Limit: 10 Sec Memory Limit: 512 MB
Submit: 602 Solved: 237
[Submit][Status][Discuss]Description
Input
一个正整数T表示数据组数
接下来T行 每行两个正整数 表示N、M
Output
Sample Input
1
4 5
Sample Output
122
HINT
T <= 10000
N, M<=10000000
HINT
Source
BZOJ 2693: jzptab( 莫比乌斯反演 )
标签:
原文地址:http://www.cnblogs.com/JSZX11556/p/4694510.html