标签:des style class blog code http
第一行一个整数n,接下来n行每行五个整数,分别表示a、b、c、d、k
共n行,每行一个整数表示满足要求的数对(x,y)的个数
100%的数据满足:1≤n≤50000,1≤a≤b≤50000,1≤c≤d≤50000,1≤k≤50000
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; #ifdef unix #define LL "%lld" #else #define LL "%I64d" #endif typedef long long qword; #define MAXN 100000 int prime[MAXN/3]; bool pflag[MAXN]; int topp=-1; int mu[MAXN]; int sum[MAXN]; void init() { int i,j; mu[1]=1; for (i=2;i<MAXN;i++) { if (!pflag[i]) { prime[++topp]=i; mu[i]=-1; } for (j=0;j<=topp&&prime[j]*i<MAXN;j++) { pflag[i*prime[j]]=true; mu[i*prime[j]]=-mu[i]; if (i%prime[j]==0) { mu[i*prime[j]]=0; } } } } qword solve(int a,int b) { int l=min(a,b); int i,j; int ls,lt; qword ret=0; for (i=1,ls=0;i<=l;i=ls+1) { ls=min((a/(a/i)),(b/(b/i))); ret+=(qword) (sum[ls]-sum[i-1])*(a/i)*(b/i); } return ret; } int main() { int nn; freopen("input.txt","r",stdin); init(); scanf("%d",&nn); int a,b,c,d,n; qword ans; int i,j; for (i=0;i<MAXN;i++)sum[i]=sum[i-1]+mu[i]; /* for (i=1;i<10;i++) { for (j=0;j<10;j++) { cout<<i<<" "<<j<<" "<<solve(i,j)<<endl; } } */ // cout<<solve(2,3); // return 0; while (nn--) { scanf("%d%d%d%d%d",&a,&b,&c,&d,&n); ans=solve((a-1)/n,(c-1)/n)-solve((a-1)/n,d/n)-solve(b/n,(c-1)/n)+solve(b/n,d/n); printf(LL "\n",ans); } }
BZOJ 2301: [HAOI2011]Problem b 莫比乌斯反演,布布扣,bubuko.com
BZOJ 2301: [HAOI2011]Problem b 莫比乌斯反演
标签:des style class blog code http
原文地址:http://www.cnblogs.com/mhy12345/p/3791822.html