codeforces 1033 D. Divisors

题目:http://codeforces.com/contest/1033/problem/D

题意:给出n个数,每个数有3~5个因子,求所有数因子乘积的个数。

思路:首先应该想到把所有数质因子分解为 x1k1,x2k2…这种形式,然后可以得到答案为(k1+1)*(k2+1)…(kn+1),但是给出数字太大无法用正常方法分解,本菜鸡做到这里就想不出来了…
题解给出根据约数个数可知,所有数都是这样构成的: pq, p2, p3,or p4 p,q均为质数
对于后面3种可以直接暴力判断,对应因子数增加。
对于第1种构成为pd的数,我们主要目的是找到同种因子的个数,那么可以直接求出这类数与其他所有数的公因数,如果有那么对应因子数目增加。
如果没有与其他数字有共同因子的,那么只需要把他本身的因子数计算出来(因为这里可能有多个相同这样的数)把它们的贡献单独乘到ans中即可

#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> LP;
const ll inf = 1e17 + 10;
const int N = 1e6 + 10;
const ll mod = 998244353 ;
const int base=131;
const double pi=acos(-1);
const double eps = 1e-6;
map<string, int>ml;


map<ll,ll> mp;
map<int,int> vi;
priority_queue<P> q;
priority_queue<P> tq;



ll b[N], vis[N], c[N],num[N], a[N],t, n, m,  k,x,y;
ll ex, ey, cnt, sum, flag,ans;

//vector<int> v[N];
vector<int> fac[N];
string s;
int dp[N][3];

char v[1005][1005];



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ll t2=pow(a[i],1.0/2.0)+eps,t3=pow(a[i],1.0/3.0)+eps,t4=pow(a[i],1.0/4.0);
		if(t3*t3*t3==a[i]) {mp[t3]+=3;continue;}
		if(t4*t4*t4*t4==a[i]) {mp[t4]+=4;continue;}
		if(t2*t2==a[i])	{mp[t2]+=2;continue;}
		b[i]=a[i];
	}
	//show2("cnt",cnt);
	for(int i=1;i<=n;i++)if(b[i])
	{
		int did=0;
		for(int j=1;j<=n;j++)
		{
			if(j==i) continue;
			ll g=__gcd(a[j],b[i]);
			if(g==1||g==b[i])
			{

				continue;
			}
			else
			{
				mp[g]++;
				mp[b[i]/g]++;
				did=1;
				break;
			}

		}
		if(!did) c[i]=b[i];
	}
	ans=1;
	//cout<<c[1]<<endl;
	for(int i=1;i<=n;i++)
	if(c[i])
	{
		ll cnt=2;

		for(int j=1;j<=n;j++)
		{
			if(c[i]==c[j]&&i!=j) cnt++,c[j]=0;
		}
		ans=ans*cnt*cnt%mod;
		//show2(c[i],ans);
	}
	for(auto x:mp) ans=ans*(x.se+1)%mod;
	cout<<ans<<endl;


}

猜你喜欢

转载自blog.csdn.net/weixin_42640692/article/details/88145353