题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675
题意:给出n,m,K,一个长度为n的数列A(1<=A[i]<=m)。对于d(1<=d<=m),有多少个长度为n的数列B满足:
(1)1<=B[i]<=m;
(2)Gcd(B[1],B[2],……,B[n])=d;
(3)恰有K个位置满足A[i]!=B[i]。
思路:
i64 p[N];
void init()
{
p[0]=1;
int i;
FOR1(i,N-1) p[i]=p[i-1]*i%mod;
}
i64 exGcd(i64 a,i64 b,i64 &x,i64 &y)
{
if(b==0)
{
x=1; y=0;
return a;
}
i64 temp=exGcd(b,a%b,x,y);
i64 t=x;
x=y;
y=t-a/b*y;
return temp;
}
i64 reverse(i64 a,i64 b)
{
i64 x,y;
exGcd(a,b,x,y);
x%=b;
if(x<0) x+=b;
return x;
}
i64 C(int n,int m)
{
return p[n]*reverse(p[m]*p[n-m]%mod,mod)%mod;
}
i64 Pow(i64 a,i64 b)
{
i64 ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
i64 a[N],g[N];
int b[N];
int n,m,K;
int main()
{
init();
Rush(n)
{
RD(m,K);
int i,j,x;
FOR1(i,m) b[i]=a[i]=0;
FOR1(i,n) RD(x),a[x]++;
for(i=m;i>=1;i--)
{
for(j=i;j<=m;j+=i) b[i]+=a[j];
}
FOR1(i,m)
{
if(b[i]>=n-K) g[i]=Pow(m/i,n-b[i])*Pow(m/i-1,b[i]-(n-K))%mod*C(b[i],n-K)%mod;
else g[i]=0;
}
for(i=m;i>=1;i--)
{
for(j=i+i;j<=m;j+=i)
{
g[i]-=g[j];
if(g[i]<0) g[i]+=mod;
}
}
FOR1(i,m-1) printf("%I64d ",g[i]);
PR(g[i]);
}
}