# 【bzoj 4589】Hard Nim

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
const int maxn=150000;
const int mod=1e9+7;
char c=getchar();int x=0;while(c<'0'||x>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int I[2]={1,500000004};
int n,m,M,len;
int is[maxn>>1],p[maxn>>1];
LL S[maxn];
inline void Fwt(LL *f,int o) {
LL Inv=I[o];
for(re int i=2;i<=len;i<<=1)
for(re int ln=i>>1,l=0;l<len;l+=i)
for(re int x=l;x<l+ln;++x) {
LL g=f[x],h=f[x+ln];
f[x]=(g+h)%mod;f[ln+x]=(g-h+mod)%mod;
f[x]=(f[x]*Inv)%mod,f[ln+x]=(f[ln+x]*Inv)%mod;
}
}
inline LL ksm(LL a,int b) {
LL S=1;while(b){if(b&1) S=S*a%mod;b>>=1;a=a*a%mod;}return S;
}
int main() {
M=50000;is[1]=1;
for(re int i=2;i<=M;i++) {
if(!is[i]) p[++p[0]]=i;
for(re int j=1;j<=p[0]&&p[j]*i<=M;j++) {
is[p[j]*i]=1;if(i%p[j]==0) break;
}
}
while(scanf("%d%d",&n,&m)!=EOF) {
memset(S,0,sizeof(S));M=0;
for(re int i=1;i<=p[0]&&p[i]<=m;i++) M=max(M,p[i]),S[p[i]]++;
len=1;while(len<=M) len<<=1;
Fwt(S,0);for(re int i=0;i<len;i++) S[i]=ksm(S[i],n);Fwt(S,1);
printf("%d\n",(int)S[0]);
}
return 0;
}

posted @ 2019-04-10 21:52  asuldb  阅读(75)  评论(0编辑  收藏