EiS 题解

· · 题解

考虑对每个 a_i 做质因数分解,则对每个质数,我们可以独立地去考虑它的情况数(像枚举二进制位),最后相乘即可。

然后考虑每个质数,设 p_i 在 a 中出现了 c_i 次(如 2 在 [2, 3, 1, 2\times2] 中出现了 3 次),则有 c_i+1 种情况。

每个 a_i 的质因数数是 O(\log a_i) 级的,所以每个测试点要考虑的质数数量不超过 \sum\log_2 a_i\le n\log_2 (5\times10^5)\le19n。

#include <bits/stdc++.h>

// using pii=std::pair<int, int>;

const int mod(1000000007);

std::mt19937 mr(std::mt19937(time(0)));

struct Hash {
    int operator() (const int & x) const {
        static int xr(mr());
        return x^xr;
    }
};

std::bitset<500000+5> isp;

int minfact[500000+5];

int n, x;

int prime[500000+5];

std::unordered_set<int, Hash> st;

void solve() {
    std::cin>>n>>x;
    st.clear();
    for(int i(1); i<=n; i++) {
        std::cin>>x;
        while(x!=1) {
            int p(minfact[x]);
            st.insert(p);
            prime[p]++;
            x/=p;
        }
    }
    int ans(1);
    for(auto i : st) {
        ans=(long long)ans*(prime[i]+1)%mod;
    }
    std::cout<<ans<<"\n";
    for(auto i : st) prime[i]=0;
}

int main() {
    n=500000;
    for(int i(2); i<=n; i++) if(!isp[i]) {
        minfact[i]=i;
        if((long long)i*i>n) continue;
        for(int j(i*i); j<=n; j+=i) minfact[j]=i, isp[j]=1;
    }
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int _;
    std::cin>>_;
    while(_--) solve();
    return 0;
}