# BZOJ 2301: [HAOI2011]Problem b( 数论 )

------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

const int maxn = 50009;

bool F[maxn];
int mu[maxn], p[maxn], pn, D;

void Init() {
memset(F, 0, sizeof F);
pn = 0;
for(int i = 2; i < maxn; i++) {
if(!F[i]) {
p[pn++] = i;
mu[i] = -1;
}
for(int j = 0; j < pn && i * p[j] < maxn; j++) {
F[i * p[j]] = true;
if(i % p[j] == 0) {
mu[i * p[j]] = 0;
break;
} else
mu[i * p[j]] = -mu[i];
}
}
mu[0] = 0;
mu[1] = 1;
for(int i = 1; i < maxn; i++)
mu[i] += mu[i - 1];
}

int f(int x, int y) {
if((y /= D) > (x /= D)) swap(x, y);
int ret = 0;
for(int L = 1, R; L <= y; L = R + 1) {
R = min(x / (x / L), y / (y / L));
ret += (mu[R] - mu[L - 1]) * (x / L) * (y / L);
}
return ret;
}

void Work() {
int T;
scanf("%d", &T);
while(T--) {
int a, b, c, d;
scanf("%d%d%d%d%d", &a, &b, &c, &d, &D);
printf("%d\n", f(b, d) + f(a - 1, c - 1) - f(a - 1, d) - f(b, c - 1));
}
}

int main() {
Init();
Work();
return 0;
}

------------------------------------------------------------------------------

## 2301: [HAOI2011]Problem b

Time Limit: 50 Sec  Memory Limit: 256 MB
Submit: 2475  Solved: 1054
[Submit][Status][Discuss]

## Output

n行，每行一个整数表示满足要求的数对(x,y)的个数

2

2 5 1 5 1

1 5 1 5 2

14

3

## HINT

100%的数据满足：1≤n≤50000，1≤a≤b≤50000，1≤c≤d≤50000，1≤k≤50000

## Source

posted @ 2016-01-07 14:29  JSZX11556  阅读(...)  评论(...编辑  收藏