94pts 求调
  • 板块P9836 种树
  • 楼主qczrz6v4nhp6u
  • 当前回复8
  • 已保存回复8
  • 发布时间2023/11/11 18:35
  • 上次更新2023/11/11 20:23:55
查看原帖
94pts 求调
654546
qczrz6v4nhp6u楼主2023/11/11 18:35

rt,思路是分解质因数后根据 d(n)=∏i(ci+1)d(n)=\prod_i(c_i+1) 贪心。

bool _Start;
#include<bits/stdc++.h>
#define Tp template<typename T>
#define Ts template<typename T,typename... _T>
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
char ibuf[1<<20],*p1=ibuf,*p2=ibuf,obuf[1<<20],*p3=obuf,*p4=obuf+(1<<20);
#define getchar() (p1==p2&&(p2=ibuf+fread(p1=ibuf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#define flush() (fwrite(obuf,1,p3-obuf,stdout),p3=obuf)
#define putchar(c) (*p3++=c,p3==p4&&flush())
struct IO{~IO(){flush();}}_;
Tp inline void read(T &x){
	x=0;static char c;static bool f;
	c=getchar(),f=0;
	for(;c<48||c>57;c=getchar())f|=c=='-';
	for(;c>47&&c<58;c=getchar())x=x*10+(c^48);
	if(c=='.'){
		static long double s;s=0.1;
		for(c=getchar();c>47&&c<58;c=getchar(),s/=10)x+=s*(c^48);
	}
	f&&(x=-x);
}
Ts inline void read(T &x,_T&... y){read(x),read(y...);}
Tp inline void write_uns(const T &x){
	if(x>9)write_uns(x/10);
	putchar(x%10^48);
}
Tp inline void write(const T &x){
	if(x<0)putchar('-'),write_uns(~x+1);
	else write_uns(x);
}
Tp inline void writesp(const T &x){write(x),putchar(' ');}
Tp inline void writeln(const T &x){write(x),putchar('\n');}
Ts inline void writesp(const T &x,const _T&... y){writesp(x),writesp(y...);}
Ts inline void writeln(const T &x,const _T&... y){writesp(x),writeln(y...);}
Tp inline void assign(T *a,int n,const T &b){while(n--)*a++=b;}
Tp inline void copy(T *a,T *b,int n){while(n--)*a++=*b++;}
Tp inline T min(const T &a,const T &b){return a<b?a:b;}
Tp inline T max(const T &a,const T &b){return b<a?a:b;}
Ts inline T min(const T &a,const T &b,const _T&... c){return min(min(a,b),c...);}
Ts inline T max(const T &a,const T &b,const _T&... c){return max(max(a,b),c...);}
Tp inline T abs(const T &a){return max(a,-a);}
Tp inline T gcd(const T &a,const T &b){return !a?b:(!b?a:gcd(b,a%b));}
Tp inline T lcm(const T &a,const T &b){return a*b/gcd(a,b);}
Ts inline T gcd(const T &a,const T &b,const _T&... c){return gcd(gcd(a,b),c...);}
Ts inline T lcm(const T &a,const T &b,const _T&... c){return lcm(lcm(a,b),c...);}
Tp inline void ckmin(T &a,const T &b){b<a&&(a=b);}
Tp inline void ckmax(T &a,const T &b){a<b&&(a=b);}
constexpr int N=1e4+5,mod=998244353;
int n,p[N],w;
struct node{
	int a,b;
	node(){a=b=0;}
	node(int _a,int _b){a=_a,b=_b;}
	bool operator <(const node &_)const{return b>_.b;}
};
node d[N][20];int cnt[N];
void decomp(int x,node *d,int &cnt){
	cnt=0;
	for(int i=2;i*i<=x;i++)
		if(x%i==0){
			d[++cnt]=node(i,0);
			for(;x%i==0;x/=i)++d[cnt].b;
		}
	if(x>1)d[++cnt]=node(x,1);
}
int v[N],arr[20][N];
bool _End;
int main(){
	fprintf(stderr,"Static Memory = %.4lf MiB\n",(&_Start-&_End)/1048576.0);
	read(n,w);
	decomp(w,d[0],cnt[0]);
	for(int i=1;i<=cnt[0];i++)
		v[d[0][i].a]=i;
	ll ans=1;
	for(int i=1;i<=n;i++){
		read(p[i]);
		decomp(p[i],d[i],cnt[i]);
		for(int j=1;j<=cnt[i];j++)
			if(v[d[i][j].a])
				arr[v[d[i][j].a]][i]=d[i][j].b;
			else ans=ans*(d[i][j].b+1)%mod;
	}
	for(int i=1;i<=cnt[0];i++){
		int b=d[0][i].b;
		std::sort(arr[i]+1,arr[i]+n+1);
		while(b){
			for(int j=1;j<=n;j++){
				++arr[i][j],b--;
				if(!b||arr[i][j]==arr[i][j+1])break;
			}
		}
		for(int j=1;j<=n;j++)
			ans=ans*(arr[i][j]+1)%mod;
	}
	writeln(ans);
	return 0;
}
2023/11/11 18:35
加载中...