51nod1769 Clarke and math 2

The title
is actually required \ (the I f * ^ k \) .
Since \ (I ^ k \) is a multiplicative function, so we only need to consider how to beg \ (the I ^ k (the p-^ A) \) .
This thing is converted into a length \ (K \) sequence, each bit is \ (\ FRAC i_k} {{{K-I_. 1}} \) , something which becomes a length \ (K \ ) value range for the \ ([0, a] \ ) is monotonically reduced number of program sequences, i.e. the \ (a \) balls placed \ (K) \ number of boxes in the embodiment, i.e., \ ( K +. 1-A \ the Choose A \) .

#include<bits/stdc++.h>
using namespace std;
int read(){int x=0,c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))x=x*10+c-48,c=getchar();return x;}
const int N=500007,P=1000000007;
int inc(int a,int b){a+=b;return a>=P? a-P:a;}
int mul(int a,int b){return 1ll*a*b%P;}
int f[N],g[N],x[N],v[N],inv[21],C[21];char s[N<<1];
int main()
{
    int n=read(),i,j,k=0,num;scanf("%s",s+1);
    for(i=1;i<=n;++i) f[i]=read();
    for(i=1;i<=strlen(s+1);++i) k=inc(mul(k,10),s[i]-48);
    for(inv[0]=inv[1]=1,i=2;i<=20;++i) inv[i]=mul(P-P/i,inv[P%i]);
    for(i=1;i<=20;++i) inv[i]=mul(inv[i-1],inv[i]);
    for(i=0;i<=20;++i) for(C[i]=inv[i],j=0;j<i;++j) C[i]=mul(C[i],i+k-j-1);
    for(i=1;i<=n;++i) v[i]=1,x[i]=i;
    for(i=2;i<=n;++i) if(x[i]^1) for(j=i;j<=n;v[j]=mul(v[j],C[num]),j+=i) for(num=0;!(x[j]%i);++num) x[j]/=i;
    for(i=1;i<=n;++i) for(j=i;j<=n;j+=i) g[j]=inc(g[j],mul(f[i],v[j/i]));
    for(i=1;i<=n;++i) printf("%d ",g[i]);
}

Guess you like

Origin www.cnblogs.com/cjoierShiina-Mashiro/p/11723179.html