跳到正文

题解

P9836题解

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

文章信息

发布
2023年11月11日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 3 分钟
题目
P9836

版本

  1. v1当前

背景

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

题目解读

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

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

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

感性理解一下:

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

具体见代码实现:

AC_Code

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

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

原文