# bzoj 2301: [HAOI2011]Problem b

## 2301: [HAOI2011]Problem b

Time Limit: 50 Sec  Memory Limit: 256 MB
Submit: 3066  Solved: 1371
[Submit][Status][Discuss]

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

[Submit][Status][Discuss]

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
#define N 50000
using namespace std;
int  mu[N+3],prime[N+3],pd[N+3];
int n,m,t,a,b,c,d,k,sum[N+3];
void calc()
{
mu[1]=1; sum[1]=mu[1];
for (int i=2;i<=N;i++)
{
if (!pd[i])
{
prime[++prime[0]]=i;
mu[i]=-1;
}
for (int j=1;j<=prime[0];j++)
{
if (i*prime[j]>N) break;
pd[i*prime[j]]=1;
if (i%prime[j]==0)
{
mu[i*prime[j]]=0;
break;
}
else
mu[i*prime[j]]=-mu[i];
}
sum[i]=sum[i-1]+mu[i];
}
}
int solve(int a,int b)
{
if (a>b) swap(a,b);
int j=0; int ans=0;
for (int i=1;i<=a;i=j+1)
{
j=min(a/(a/i),b/(b/i));
ans=ans+(sum[j]-sum[i-1])*(a/i)*(b/i);
}
return ans;
}
int main()
{
scanf("%d",&t);
calc();
for (int T=1;T<=t;T++)
{
scanf("%d%d%d%d%d",&a,&c,&b,&d,&k); a--; b--;
c/=k; d/=k;  a/=k; b/=k;
int ans=solve(c,d)-solve(a,d)-solve(b,c)+solve(a,b);
printf("%d\n",ans);
}
return 0;
}

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客