题解 P6298 【齿轮】
StudyingFather · · 题解
我们设
显然有:
然而
我们可以容斥。倒序枚举
时间复杂度?求
总时间复杂度
// Problem : P6298 齿轮
// Contest : Luogu Online Judge
// URL : https://www.luogu.com.cn/problem/P6298
// Author : StudyingFather
// Site : https://studyingfather.com
// Memory Limit : 128 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <iostream>
#define MOD 1000000007
using namespace std;
long long f[1000005],inv[1000005],invf[1000005],g[1000005];
int t[1000005];
long long c(int x,int y)
{
if(x<y)return 0;
return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
ios::sync_with_stdio(false);
int n,m,k;
cin>>n>>m>>k;
f[0]=invf[0]=1;
for(int i=1;i<=n;i++)//预处理
{
if(i!=1)inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
else inv[1]=1;
f[i]=f[i-1]*i%MOD;
invf[i]=invf[i-1]*inv[i]%MOD;
}
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
t[x]++;
}
for(int i=m;i;i--)
{
int cnt=0;
for(int j=1;i*j<=m;j++)
{
cnt+=t[i*j];
g[i]=(g[i]-g[i*j]+MOD)%MOD;//容斥的过程
}
g[i]=((g[i]+c(cnt,k))%MOD+MOD)%MOD;
}
for(int i=1;i<=m;i++)
cout<<g[i]<<' ';
return 0;
}