# BZOJ 2693: jzptab( 莫比乌斯反演 )

化简之后就只须求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]

## Output

T行 每行一个整数 表示第i组数据的结果

1

4 5

122

HINT
T <= 10000

N, M<=10000000

## Source

posted @ 2015-08-01 18:50  JSZX11556  阅读(200)  评论(0编辑  收藏  举报