# [CQOI2015][bzoj3930] 选数 [杜教筛+莫比乌斯反演]

Code：

 1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<map>
6 #define ll long long
7 using namespace std;
9     ll re=0,flag=1;char ch=getchar();
10     while(ch>'9'||ch<'0'){
11         if(ch=='-') flag=-1;
12         ch=getchar();
13     }
14     while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
15     return re*flag;
16 }
17 ll pri[2000010],tot=0,mu[2000010],n,K,L,R;bool vis[2000010];
18 ll MOD=1e9+7;
19 void init(){
20     ll i,j,k;mu[1]=1;
21     for(i=2;i<=2000000;i++){
22         if(!vis[i]){
23             pri[++tot]=i;mu[i]=-1;
24         }
25         for(j=1;j<=tot;j++){
26             k=i*pri[j];if(k>2000000) break;
27             vis[k]=1;
28             if(i%pri[j]==0){
29                 mu[k]=0;break;
30             }
31             mu[k]=-mu[i];
32         }
33     }
34     for(i=2;i<=2000000;i++) mu[i]=mu[i-1]+mu[i];
35 }
36 ll sum1(ll x){return x*(x+1)/2;}
37 map<ll,ll>m;
38 ll S2(ll x){
39     if(x<=2000000) return mu[x];
40     ll re=1,i,j;
41     if(m[x]) return m[x];
42     for(i=2;i<=x;i=j+1){
43         j=x/(x/i);
44         re-=((j-i+1)*S2(x/i))%MOD;
45         re=(re+MOD)%MOD;
46     }
47     return m[x]=re;
48 }
49 ll ppow(ll a,ll b){
50     ll re=1;
51     while(b){
52         if(b&1) re=re*a%MOD;
53         a=a*a%MOD;b>>=1;
54     }
55     return re%MOD;
56 }
57 int main(){
58     init();
68 }