CF915G 题解
Lucky_Xiang · · 题解
题目
CF915G
分析
由题意,得:
但是,这时候用数论分块显然是跑不过去的。考虑用差分优化算法。
差分
引理:
可以发现
这样,就可以用
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mn=2000010;
const int N=2000000;
const int mod=1000000007;
LL qmi(LL a,LL b)
{
LL s=1;
while(b)
{
if(b&1)s=s*a%mod;
a=a*a%mod;
b>>=1;
}
return s;
}
int n,k;
LL d[mn],h[mn],f[mn];
int mu[mn];
int p[mn],tot;
bool st[mn];
void init()
{
mu[1]=1;
for(int i=2;i<=N;i++)
{
if(!st[i])p[++tot]=i,mu[i]=-1;
for(int j=1;i*p[j]<=N;j++)
{
st[i*p[j]]=1;
if(i%p[j]==0)
{
mu[i*p[j]]=0;
break;
}
mu[i*p[j]]=-mu[i];
}
}
for(int i=1;i<=k;i++)
{
d[i]=qmi(i,n);
h[i]=d[i]-d[i-1];
}
}
LL res,sum;
int main()
{
cin>>n>>k;
init();
for(int i=1;i<=k;i++)
{
for(int j=1;j<=k/i;j++)
{
f[i*j]+=mu[j]*h[i];
f[i*j]%=mod;
}
}
for(int i=1;i<=k;i++)
{
sum+=f[i];
sum=(sum%mod+mod)%mod;
res+=(sum^i);
res%=mod;
}
cout<<res<<endl;
return 0;
}