【反演复习计划】【bzoj3529】数表

Orz PoPoQQQ大爷

按照他ppt的解法,这题可以划归到之前的题了OrzOrz

跪wy写的题解(Stealth Assassin)https://www.luogu.org/wiki/show?name=%E9%A2%98%E8%A7%A3+P3312

 1 #include<bits/stdc++.h>
 2 #define N 100005
 3 #define fi first
 4 #define sc second
 5 using namespace std;
 6 typedef long long ll;
 7 int Q,maxn,cnt,prime[N],mu[N],d[N];
 8 int c[10*N],ans[N],vis[N];
 9 pair<int,int> f[N];
10 struct Query{int n,m,a,id;}q[N];
11 bool operator<(Query x,Query y){return x.a<y.a;}
12 inline int lowbit(int x){return (x&(-x));}
13 inline void add(int x,int val){
14     for(int i=x;i<=maxn;i+=lowbit(i))c[i]+=val;
15 }
16 inline int query(int x){
17     int ans=0;
18     for(int i=x;i;i-=lowbit(i))ans+=c[i];
19     return ans;
20 }
21 inline void calcmu(){
22     cnt=0;memset(vis,1,sizeof(vis));mu[1]=1;
23     for(int i=2;i<=maxn;i++){
24         if(vis[i]){prime[++cnt]=i;mu[i]=-1;}
25         for(int j=1;j<=cnt;j++){
26             int t=prime[j]*i;if(t>maxn)break;
27             vis[t]=0;
28             if(i%prime[j]==0){mu[t]=0;break;}
29             mu[t]=-mu[i];
30         }
31     }
32     for(int i=1;i<=maxn;i++)
33     for(int j=i;j<=maxn;j+=i)f[j].fi+=i;
34     for(int i=1;i<=maxn;i++)f[i].sc=i;
35 }
36 inline void work(int x){
37     int id=q[x].id,n=q[x].n,m=q[x].m;
38     for(int i=1,j=1;i<=n;i=j+1){
39         j=min(n/(n/i),m/(m/i));
40         ans[id]+=(n/i)*(m/i)*(query(j)-query(i-1));
41     }
42 }
43 inline int read(){
44     int f=1,x=0;char ch;
45     do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
46     do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
47     return f*x;
48 }
49 int main(){
50     Q=read();
51     for(int i=1;i<=Q;i++){
52         q[i].n=read();q[i].m=read();q[i].a=read();q[i].id=i;
53         if(q[i].n>q[i].m)swap(q[i].n,q[i].m);
54         maxn=max(maxn,q[i].n);
55     }
56     calcmu();
57     sort(q+1,q+Q+1);sort(f+1,f+maxn+1);int now=0;
58     for(int i=1;i<=Q;i++){
59         while(now+1<=maxn&&f[now+1].fi<=q[i].a){
60             ++now;
61             for(int j=f[now].sc;j<=maxn;j+=f[now].sc)
62             add(j,f[now].fi*mu[j/f[now].sc]);
63         }
64         work(i);
65     }
66     for(int i=1;i<=Q;i++)printf("%d\n",ans[i]&0x7fffffff);
67     return 0;
68 }

 

posted @ 2017-05-22 20:30  zcysky  阅读(250)  评论(0编辑  收藏  举报