# [BZOJ2301][HAOI2011]Problem b

[BZOJ2301][HAOI2011]Problem b

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

2
2 5 1 5 1
1 5 1 5 2

14
3

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

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;

const int BufferSize = 1 << 16;
inline char Getchar() {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
}
int x = 0, f = 1; char c = Getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = Getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = Getchar(); }
return x * f;
}

#define maxn 50010
#define LL long long

int prime[maxn], cp, mu[maxn], smu[maxn];
bool vis[maxn];
void init() {
mu[1] = smu[1] = 1;
for(int i = 2; i < maxn; i++) {
if(!vis[i]) prime[++cp] = i, mu[i] = -1;
for(int j = 1; i * prime[j] < maxn && j <= cp; j++) {
vis[i*prime[j]] = 1;
if(i % prime[j] == 0){ mu[i*prime[j]] = 0; break; }
mu[i*prime[j]] = -mu[i];
}
smu[i] = smu[i-1] + mu[i];
}
return ;
}

LL f(int n, int m, int k) {
LL ans = 0;
n /= k; m /= k;
for(int i = 1, lst; i <= min(n, m); i = lst + 1) {
lst = min(n / (n / i), m / (m / i));
ans += (LL)(n / i) * (m / i) * (smu[lst] - smu[i-1]);
}
return ans;
}

int main() {
init();