跳到正文

题解

EiS 题解

c_legg约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年6月22日
收录
2026年6月22日
更新
2026年11月11日
篇幅
约 3 分钟
题目
CF2236F1

版本

  1. v1当前

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

然后考虑每个质数,设 pip_i 在 aa 中出现了 cic_i 次(如 22 在 [2,3,1,2×2][2, 3, 1, 2\times2] 中出现了 33 次),则有 ci+1c_i+1 种情况。

每个 aia_i 的质因数数是 O(log⁡ai)O(\log a_i) 级的,所以每个测试点要考虑的质数数量不超过 ∑log⁡2ai≤nlog⁡2(5×105)≤19n\sum\log_2 a_i\le n\log_2 (5\times10^5)\le19n。

C++
#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;
}
原文