# 【BZOJ2301】Problem B

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

【题解思路】

【code】

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(k,i,j) for(int k = i;k <= j; ++k)
#define FOR(k,i,j) for(int k = i;k >= j; --k)
int x = 0,f = 1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0'; ch=getchar();}
return x*f;
}
const int mod = 1e9+7;
const int mxn = 5e4+5;
inline void file(){
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
int a,b,c,d,k;
inline void in(){
a--,c--;
}
bool v[mxn];
int prime[mxn],miu[mxn],sum[mxn];
inline void getmiu(){
memset(v,0,sizeof(v));
int tot(0);
miu[1] = 1;
for(int i = 2;i <= mxn; ++i){
if(!v[i]){
prime[++tot] = i;
miu[i]=-1;
}
for(int j = 1;j <= tot && i*prime[j]<= mxn; ++j){
v[i*prime[j]] = 1;
if(i%prime[j]==0){
miu[prime[j]*i] = 0;
break;
}else miu[prime[j]*i] = -miu[i];
}
}
for(int i = 1;i <= mxn; ++i) sum[i] = sum[i-1]+miu[i];
}
inline int wor(int n,int m){
n/=k,m/=k;
if(n>m) swap(n,m);
int ret(0);
for(int i = 1,last;i <= n; i = last+1){
last = min(m/(m/i),n/(n/i));
ret += (n/i)*(m/i)*(sum[last]-sum[i-1]);
}
return ret;
}
inline void print(){
printf("%d\n",wor(a,c)+wor(b,d)-wor(a,d)-wor(b,c));
}
int T;
int main(){
//    file();
getmiu();
}