求助
  • 板块P9836 种树
  • 楼主Liuyc07
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/11 21:55
  • 上次更新2023/11/12 00:38:33
查看原帖
求助
752318
Liuyc07楼主2023/11/11 21:55

WA 了 16,17,20,23,24

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#define int long long
#define gc getchar
#define rep(i,a,b) for(int i = (a); i <= (b); i ++ )
#define rop(i,a,b) for(int i = (a); i < (b); i ++ )
#define per(i,a,b) for(int i = (a); i >= (b); i -- )
#define por(i,a,b) for(int i = (a); i > (b); i -- )
using namespace std;

const int N = 1e4 + 10;
const int p = 998244353;

int n,w,a[N],pw[N]; // 每个因子的最小出现次数 + 1
int ans = 1,cnt[N];
int f[N];

int read(){
    int res = 0, f = 1; char ch = gc();
    while(ch < '0' or ch > '9'){
        if(ch == '-') f = -1;
        ch = gc();
    }
    while(ch >= '0' and ch <= '9') res = (res << 3) + (res << 1) + (ch ^ 48), ch = gc();
    return res * f;
}

void file(){
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
}

signed main(){
    // file();
    n = read(); w = read();
    rep(i,1,N) pw[i] = 100000;
    rep(i,1,n) a[i] = read();
    rep(i,1,n){
        rep(j,2,sqrt(a[i])){
            int c = 1;
            while(a[i] % j == 0){
                a[i] /= j;
                c ++;
                cnt[j] ++;
            }
            pw[j] = min(pw[j],c);
            f[j] ++;
            ans *= c;
            ans %= p;
        }
        if(a[i] != 1){
            cnt[a[i]] ++;
            pw[a[i]] = min(pw[a[i]],2ll);
            ans *= 2;
            ans %= p;
        }
    }
    rep(i,1,N) if(f[i] != n) pw[i] = 1;
    rep(i,2,sqrt(w)){
        int c = 1;
        if(w % i == 0){
            while(w % i == 0){
                c ++;
                w /= i;
            }
            if(!cnt[i]) ans *= c;
            else{
                ans /= pw[i];
                ans *= (pw[i] + (c - 1));
            }
            ans %= p;
        }
    }
    if(w != 1 and !cnt[w]){
        ans *= 2;
        ans %= p;
    }
    else if(w != 1){
        ans /= pw[w];
        ans *= (pw[w] + 1);
        ans %= p;
    }
    printf("%lld",ans % p);
    return 0;
}
2023/11/11 21:55
加载中...