RT,哪里假了awa,思路是分解质因数,考虑将w质因子放到pi中的贡献
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e4 + 10;
const int mod = 998244353;
LL n, w;
LL a[N];
LL p[N][100], c[N][100], tot;
LL sum[N];
void divide(int x)
{
tot ++;
int cnt = 0;
for (int i = 2; i * i <= x; i ++ )
if (x % i == 0)
{
p[tot][++ cnt] = i, c[tot][cnt] = 0;
while (x % i == 0)
{
x /= i;
c[tot][cnt] ++;
}
}
if (x > 1)
p[tot][++ cnt] = x, c[tot][cnt] = 1;
p[tot][0] = cnt;
sum[tot] = 1; // 每个数因数个数
for (int i = 1; i <= cnt; i ++ )
sum[tot] = sum[tot] * (c[tot][i] + 1);
/*
for (int i = 1; i <= cnt; i ++ )
cout << p[tot][i] << '^' << c[tot][i] << endl;
cout << endl;*/
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> w;
divide(w);
for (int i = 1; i <= n; i ++ )
{
cin >> a[i];
divide(a[i]);
}
/*
for (int i = 1; i <= tot; i ++ )
cout << sum[i] << ' ';*/
LL ans = 1;
for (int i = 1; i <= p[1][0]; i ++ ) // w各个因数
{
int v = p[1][i];
int cnt = 0;
for (int j = 2; j <= tot; j ++ )
for (int k = 1; k <= p[j][0]; k ++ )
if (p[j][k] == v) cnt ++;
if (cnt == n) ans = ans * c[1][i] % mod;
else ans = ans * (c[1][i] + 1) % mod;
}
for (int i = 2; i <= tot; i ++ )
{
ans = ans * sum[i] % mod;
//cout << sum[i] << endl;
}
cout << ans << endl;
return 0;
}