# bzoj2301: [HAOI2011]Problem b

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=50005;
int mo[nmax],prime[nmax],cnt=0;bool vis[nmax];
void init(){
mo[1]=1;
rep(i,2,nmax-1){
if(!vis[i]) prime[++cnt]=i,mo[i]=-1;
rep(j,1,cnt){
if(i*prime[j]>=nmax) break;
vis[i*prime[j]]=1;
if(i%prime[j]==0){
mo[i*prime[j]]=0;break;
}
mo[i*prime[j]]=-mo[i];
}
}
rep(i,2,nmax-1) mo[i]+=mo[i-1];
}
/*void init(){
mo[1]=1;
rep(i,2,nmax-1){
if(!vis[i]) prime[++cnt]=i,mo[i]=-1;
rep(j,1,cnt){
int tmp=prime[j];
if(i*tmp>=nmax) break;
vis[i*tmp]=1;
if(i%tmp==0) {
mo[i*tmp]=0;break;
}
mo[i*tmp]=-mo[i];
}
}
rep(i,2,nmax-1) mo[i]+=mo[i-1];
}*/
ll cal(int n,int m,int k){
ll ans=0;n/=k;m/=k;
int last,t=min(n,m);
for(int i=1;i<=t;i=last+1){
last=min(n/(n/i),m/(m/i));
ans+=(ll)(m/i)*(n/i)*(mo[last]-mo[i-1]);
}
return ans;
}
int main(){
init();
rep(i,1,n){
printf("%lld\n",cal(b,d,k)-cal(b,c-1,k)-cal(a-1,d,k)+cal(a-1,c-1,k));
}
return 0;
}



## 2301: [HAOI2011]Problem b

Time Limit: 50 Sec  Memory Limit: 256 MB
Submit: 3780  Solved: 1684
[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]
posted @ 2016-09-10 14:44  BBChq  阅读(...)  评论(...编辑  收藏