教练说测评系统的问题,但洛谷用的不也是linux吗?
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 10;
const ll mod = 998244353;
ll n, w, ans = 1;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll d[maxn];
int tot, cnt, num;
bool vis[maxn];
ll prime[maxn];
ll dp[maxn][maxn];
ll e[maxn];
void pri(){
for(int i = 2; i <= w; ++i){
if(!vis[i]) prime[++cnt] = i;
for(int j = 1; j <= cnt && i * prime[j] <= w; ++j){
vis[i * prime[j]] = 1;
if(i % prime[j] == 0) break;
}
}
}
void pre(){
pri();
for(int i = 1; i <= cnt && w; ++i){
while(w % prime[i] == 0){
c[++tot] = prime[i];
w /= prime[i];
}
}
}
void check(){
ll res = 1;
for(int i = 1; i <= n; ++i) b[i] = 0;
for(int i = 1; i <= n; ++i){
for(int j = 1; j * j <= a[i]; ++j){
if(a[i] % j == 0){
++b[i];
if(j * j != a[i]) ++b[i];
}
}
res = res * b[i] % mod;
}
ans = max(ans, res);
}
void dfs2(int now, int sum){
if(now == n + 1 || sum == tot + 1){
check();
return;
}
a[now] *= c[sum];
dfs2(now, sum + 1);
dfs2(now + 1, sum + 1);
a[now] /= c[sum];
dfs2(now + 1, sum);
}
bool col[maxn];
void dfs1(int now){
if(now == n + 1){
dfs2(1, 1);
return;
}
for(int i = 1; i <= n; ++i){
if(col[i]) continue;
a[now] = d[i];
col[i] = 1;
dfs1(now + 1);
col[i] = 0;
}
}
void sol(){
scanf("%lld%lld", &n, &w);
for(int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
if(w == 1){
for(int i = 1; i <= n; ++i){
for(int j = 1; j * j <= a[i]; ++j){
if(a[i] % j == 0){
++b[i];
if(j * j != a[i]) ++b[i];
}
}
ans = ans * b[i] % mod;
}
}
else if(n == 1){
a[1] *= w;
for(int j = 1; j * j <= a[1]; ++j){
if(a[1] % j == 0){
ans = (ans + 1) % mod;
if(j * j != a[1]) ans = (ans + 1) % mod;
}
}
--ans;
}
else if(n <= 5){
pre();
for(int i = 1; i <= n; ++i)
d[i] = a[i];
dfs1(1);
}
printf("%lld", ans);
}
int main(){
// freopen("plant.in", "r", stdin);
// freopen("plant.out", "w", stdout);
sol();
return 0;
}