P9836题解

· · 题解

背景

考场预处理 RE,快乐保龄。(直接 AFO)

题目解读

关于神秘的小学奥数有一个因数个数定理:

对于一个数 N=\prod\limits_{i=1}^{k}{p_i^{\alpha_i}},它有 S=\prod\limits_{i=1}^{k}(\alpha_i+1) 个正因数。其中 p_i 为质数,\alpha_i 为正整数。

由于化肥的特殊使用性质,我们考虑把化肥重量 w 的质因数一个一个施给树木。那么对于质因数 p 珂以施给 n 棵树中最少拥有质因子 p 的树木。

感性理解一下:

对于所有 n 个数,产生的贡献是所有数的各个质因数个数加一的乘积,显然给越小的加,增加的贡献就越大。

具体见代码实现:

AC_Code

#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
const int N=1e4+5;
typedef long long LL;
const LL P=998244353;
int n,w;
int h;
vector <int> p;
bool vis[N];
LL ans=1;
priority_queue <int,vector<int>,greater<int> >q[2000]; 
void allprime(){
    for(int i=2;i<=N-5;i++){//考场上就是这里写了 i<=N 拜见了祖宗
        if(vis[i]) continue;
        p.push_back(i);
        for(int j=1;i*j<=N-5;j++) vis[i*j]=true; 
    }
}
inline LL qp(LL a,LL b){
    LL res=1;
    while(b){
        if(b&1) res=res*a%P;
        a=a*a%P;
        b>>=1;
    }
    return res;
}
int main(){
//  freopen("plant3.in","r",stdin);
//  freopen("plantmy.out","w",stdout);
    scanf("%d%d",&n,&w);
    allprime();
//  cout<<p.size()<<endl;
    for(int i=1;i<=n;i++){
        scanf("%d",&h);
        for(int j=0;j<p.size();j++){
            int cnt=0;
            while(!(h%p[j])) h/=p[j],cnt++;
            ans=ans*(LL)(cnt+1)%P;
            q[j].push(cnt+1);
        }
    }
    for(int i=0;i<p.size()&&w!=1;i++){
        while(w%p[i]==0){
            w/=p[i];
            int temp=q[i].top();
        //用优先队列维护常数有亿点大
            ans=(ans+(ans*qp(temp,P-2))%P)%P;
        //选取最小的加一,记录所增加的贡献。
            q[i].pop();
            q[i].push(temp+1);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

如有锅,请大佬马上在评论上爆踩我。