bzoj3529: [Sdoi2014]数表
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define N 100000 typedef long long ll; struct P{ int x,y,num; ll a; bool operator<(P b)const{ return a<b.a; } }w[N+20]; struct pa{ int x; ll y; bool operator<(pa a)const{ return y<a.y; } }c[N+20]; int mindiv[N+20]; int zhin,zhi[N+20]; int u[N+20]; ll f[N+20]; int n,m; void shai(int M){ for(int i=1;i<=M;i++)mindiv[i]=i; u[1]=1; for(int i=2;i<=M;i++){ if(mindiv[i]==i)zhi[++zhin]=i,u[i]=-1; for(int j=1;j<=zhin&&zhi[j]<=mindiv[i]&&(ll)zhi[j]*i<=M;j++){ if(mindiv[i]==zhi[j]){ u[zhi[j]*i]=0; }else u[zhi[j]*i]=-u[i]; mindiv[zhi[j]*i]=zhi[j]; } } } int lowbit(int x){ return x&-x; } int t; ll ans[N+20]; ll a[N+20]; ll F[N+20]; void add(int x,ll y){ for(int i=x;i<=N;i+=lowbit(i))a[i]+=y; } ll ask(int x){ ll tot=0; for(int i=x;i>=1;i-=lowbit(i))tot+=a[i]; return tot; } int l; void gg(ll x){ while(l<N&&c[l+1].y<=x){ l++; for(int j=1;j*c[l].x<=N;j++)add(j*c[l].x,c[l].y*u[j]); } } int main(){ shai(100000); for(int i=1;i<=N;i++){ int j; for(j=1;j*j<i;j++){ if(i%j==0)f[i]+=j+i/j; } if(j*j==i)f[i]+=j; c[i]=(pa){i,f[i]}; } scanf("%d",&t); for(int i=1;i<=t;i++){ scanf("%d%d%lld",&w[i].x,&w[i].y,&w[i].a); w[i].num=i; } sort(w+1,w+t+1); sort(c+1,c+N+1); for(int i=1;i<=t;i++){ gg(w[i].a); n=w[i].x; m=w[i].y; ll no=n*m; int lim=min(m,n); int l1,r1; for(l1=1,r1;l1<=lim;l1=r1+1){ ans[w[i].num]+=(ask(r1=min(n/(n/l1),m/(m/l1)))-ask(l1-1))*(n/l1)*(m/l1); } } for(int i=1;i<=t;i++)printf("%d\n",ans[i]&0x7fffffff); }