求因子个数

发布时间 2023-07-05 20:48:21作者: Qiansui

下面放个求因子个数的方法

#define ll long long
ll calc(ll x){//求因子个数
	if(cnt.count(x)) return cnt[x];
	ll ans=1;
	for(ll i=2;i*i<=x;++i){
		if(x%i==0){
			ll c=0;
			while(x%i==0){
				++c;
				x/=i;
			}
			ans*=c+1;
		}
	}
	if(x!=1) ans*=2;
	return ans;
}