题解:CF2176F Omega Numbers
Network_Flow · · 题解
题目中给出
有一个重要的观察:因为
任务转为计数,发现这个
设
除以
那也就变成考虑
最后
#include <iostream>
#include <cstdio>
#define ll long long
#define N 300005
#define INF (ll)1e18
#define PII pair<ll, ll>
#define lowbit(x) x&(-x)
using namespace std;
inline ll rd(){
ll res=0, f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch^48), ch=getchar();
return (f>0?res:-res);
}
ll n, k, w[N], p[N], tot, K, a[N], cnt[N][10], ans;
ll g[N][10][10], f[N][10][10];
bool isp[N];
const ll mod=998244353;
ll ksm(ll a, ll b){
ll res=1;
while(b){
if(b&1) res=res*a%mod;
a=a*a%mod, b>>=1;
}
return res;
}
void prime(){
isp[1]=1;
for(int i=2; i<=N-5; i++){
if(!isp[i]) p[++tot]=i, w[i]=1;
for(int j=1; j<=tot&&i*p[j]<=N-5; j++){
isp[i*p[j]]=1;
w[i*p[j]]=w[i]+(i%p[j]>0);
if(i%p[j]==0) break;
}
}
}
void solve(){
n=rd(), K=rd(), ans=0;
for(int i=1; i<=n; i++) for(int j=0; j<=6; j++) cnt[i][j]=0;
for(int i=1; i<=n; i++) a[i]=rd(), cnt[a[i]][w[a[i]]]++;
for(int i=1; i<=n; i++)
for(int j=i*2; j<=n; j+=i)
for(int k=0; k<=6; k++) cnt[i][k]=(cnt[i][k]+cnt[j][k]);
for(int x=0; x<=6; x++)
for(int y=x; y<=6; y++)
for(int k=n; k; k--){
f[k][x][y]=g[k][x][y]=(x==y?(cnt[k][x]*(cnt[k][y]-1)/2)%mod:cnt[k][x]*cnt[k][y]%mod);
for(int i=2*k; i<=n; i+=k) g[k][x][y]=(g[k][x][y]-g[i][x][y]+mod)%mod;
}
for(int x=0; x<=6; x++)
for(int y=x; y<=6; y++)
for(int k=n; k; k--)
ans=(ans+g[k][x][y]*ksm((x+y-w[k]+mod)%mod, K)%mod)%mod;
printf("%lld\n", ans);
}
int main(){
prime();
for(ll tt=rd(); tt--; solve());
return 0;
}