题意就是已知 f 求
只需求
考虑
因为 1K 是积性函数,想到尝试线性筛,所以我们只需考虑(1K)(pr) 值。只有一个质因数就很好算了:
(1K)(pr)=∑i0≤i1≤i2≤...ik≤r1=(r+K−1r)
这样就可以愉快的线性筛了。
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=500005,MOD=1e9+7;
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
int getint_M(){
char ch=gc(); LL res=0;
while(!('0'<=ch&&ch<='9')) ch=gc();
while('0'<=ch&&ch<='9') res=((res<<3)+(res<<1)+ch-'0')%MOD, ch=gc();
return res;
}
int n,f[maxn],K,g[maxn];
int h[maxn],pw[maxn],p[maxn],inv[105];
bool vis[maxn];
void get_h(){
h[1]=1;
for(int i=2;i<=n;i++){
if(!vis[i]) p[++p[0]]=i, h[i]=K, pw[i]=1;
for(int j=1;j<=p[0]&&(LL)i*p[j]<=n;j++){
vis[i*p[j]]=true;
if(i%p[j]==0){ int r=(pw[i*p[j]]=pw[i]+1); h[i*p[j]]=(LL)h[i]*(r+K-1)%MOD*inv[r]%MOD; break; }
pw[i*p[j]]=1; h[i*p[j]]=(LL)h[i]*K%MOD;
}
}
}
int main(){
inv[1]=1; for(int i=2;i<=100;i++) inv[i]=(LL)(MOD-MOD/i)*inv[MOD%i]%MOD;
n=getint_M(); K=getint_M();
for(int i=1;i<=n;i++) f[i]=getint_M();
get_h();
for(int i=1;i<=n;i++)
for(int j=1;(LL)i*j<=n;j++) (g[i*j]+=(LL)h[i]*f[j]%MOD)%=MOD;
for(int i=1;i<=n;i++) printf("%d ",g[i]);
return 0;
}