WA 82 pts 求助
  • 板块P9836 种树
  • 楼主abensyl
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/11/11 22:23
  • 上次更新2023/11/12 08:35:00
查看原帖
WA 82 pts 求助
641163
abensyl楼主2023/11/11 22:23

提交记录

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 10, M = 10003;
const int mod = 998244353;
map<int,int> mp;
vector<int> vc;
priority_queue<pair<int,int> > pq[N];
int p[M];
int devide(int a) {
	if(a==1) return 1;
	int res=1;
	for(int i=2;i*i<=a;++i) {
		if(a%i) continue;
		int zc=1;
		while(a%i==0) a/=i,zc++;
		res*=zc;
		res%=mod;
	}
	if(a!=1) res*=2;
	return res%mod;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr),
	cout.tie(nullptr);
	int n,w;
	cin>>n>>w;
	if(w!=1) {
		int a=w;
		for(int i=2;i*i<=a;++i) {
			if(a%i) continue;
			int zc=0;
			while(a%i==0) a/=i,zc++;
			mp[i]=zc;
		}
		if(a!=1) mp[a]=1;
		for(auto c:mp) vc.push_back(c.first);
	}
	for(int i=1;i<=n;++i) {
		cin>>p[i];
		for(int j=0;j<vc.size();++j) {
			int lk=p[i],cnt=0,c=vc[j];
			while(lk%c==0) lk/=c,cnt++;
			pq[j].push(make_pair(-cnt,i));
		}
	}
	for(int i=0;i<vc.size();++i) {
		int ct=mp[vc[i]];
		while(ct--) {
			auto tp=pq[i].top();
			pq[i].pop();
			p[tp.second]*=vc[i];
			pq[i].push(make_pair(-tp.first-1,tp.second));
		}
	} int res=1;
	for(int i=1;i<=n;++i) res=(res*devide(p[i]))%mod;
	cout<<res<<'\n';
	return 0;
}
2023/11/11 22:23
加载中...