Divisors 1033D 质数大类

题目链接:https://codeforces.com/problemset/problem/1033/D

大意:

500个数字[1,2e18],每个数字有3到5个约数(分为a*a,a*a*a,a*a*a*a,a*b四种情况)

求他们全部数字的乘积有多少个约数?

分析:

对于前三种(a^b,1<b<5),特判,用二分的方式找有没有数的平方或三次方是它,找不到就说明没有

把前三种都分解之后,用一个map记录质因数出现的次数

如果只有前三种,那就清静了,约数个数就是(每个质因数的次数+1)的积

为了处理第四种,我们要想点办法

先想一想,如果对于每个第四种,他们的质因数(a*b)都不相同,那我们是不是很容易求出他们对答案:积的约数的影响?

如果有k个第四种,那么答案就是前三种计算出的答案*(4^k),然而,在所有的第四种数字种,也有跟后者有公共的质因数的

,这里就很巧妙了,因为对于没有公共质因数的,我们可以直接算它对答案的影响,不用分解他,而有质因数的,我们可以根据GCD的算法计算他们的GCD,如果GCD为1,那就说明没用公共质因数,如果不为1,那我们也求出这个数的组成了,直接把他分解,把质因数的次数加到前三种的map中去,这样每个数对答案的影响就分成了2块(map,4^k),最后答案也就出来了

代码:

//Problem:
//Date:
//Skill:
//Bug:
/////////////////////////////////////////Definations/////////////////////////////////////////////////
//循环控制
#define CLR(a) memset((a),0,sizeof(a))
#define F(i,a,b) for(int i=a;i<=int(b);++i)
#define F2(i,a,b) for(int i=a;i>=int(b);--i)
#define RE(i,n)  for(int i=0;i<int(n);i++)
#define RE2(i,n) for(int i=1;i<=int(n);i++)
//输入输出
//#define INC(c) do{scanf("%c",&c);}while(isspace(c))
//#define ON cout<<endl
#define PII pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
////////////////////////////////////////Options//////////////////////////////////////////////////////
typedef long long ll;
#define stdcpph
#define CPP_IO

#ifdef stdcpph
#include<bits/stdc++.h>
#else
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#ifdef CPP_IO
#include<iostream>
#include<iomanip>
#include<string>
#else
#include<stdio.h>
#endif
#endif
////////////////////////////////////////Basic Functions//////////////////////////////////////////////
template<typename INint>
inline void IN(INint &x)
{
	x = 0; int f = 1; char c; cin.get(c);
	while (c<'0' || c>'9') { if (c == '-')f = -1; cin.get(c); }
	while (c >= '0'&&c <= '9') { x = x * 10 + c - '0'; cin.get(c); }
	x *= f;
}
template<typename INint>
inline void OUT(INint x)
{
	if (x > 9)OUT(x / 10);
	cout.put(x % 10 + '0');
}
////////////////////////////////////////Added Functions//////////////////////////////////////////////
const int maxn = int(1);
map<ll, ll>ma,ol;
ll gcd(ll a, ll b)
{
	if (a < b)swap(a, b);
	return b ? gcd(b, a%b) : a;
}
ll isn(ll x,ll n)
{
	ll le(0), ri(pow(2e18+1e8,1./n));
	while (le + 1 != ri)
	{
		ll mid = ((le + ri) >> 1);
		ll res(1); RE(i, n)res *= mid;
		if (res == x)return mid;
		else if (res > x)ri = mid;
		else le = mid;
	}
	return 0;
}
ll a[505];
int n;
ll cnt(0);
void deal(ll x,ll pos)
{
	if (x == 1)return;
	ll res = isn(x, 3);
	if (res)
	{
		ma[res] += 3; return;
	}
	res = isn(x, 2);
	if (res)
	{
		ll res2 = isn(res, 2);
		if (res2)
			ma[res2] += 4;
		else 
			ma[res] += 2;
		return;
	}

	ll g; int i;
	for( i=1;i<=n;++i)if (i != pos)
	{
		res = gcd(a[i], x);
		if (res == 1)continue;
		if (res == x)g = res;
		else {
			++ma[res];
			++ma[x / res];
			break;
		}
	}
	if (i == n + 1)++ol[x];
}
////////////////////////////////////////////Code/////////////////////////////////////////////////////
int main()
{
	//freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
	int T(1), times(0);
#ifdef CPP_IO// CPP_IO
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//cin >> T;
#else
	//IN(T);
#endif 
	/////////////////////////////////////////////////////////////////////////////////////////////////
	while (++times, T--)
	{ cin >> n;
		RE2(i, n)
		{
			cin >> a[i];
		}
		RE2(i, n)
			deal(a[i],i);
		ll ans(1);
		for (auto x : ma)
			ans *= x.second + 1, ans %= 998244353;
		for(auto x:ol)
		{
			ans *=x.second+1; ans %= 998244353; 
			ans *= x.second + 1; ans %= 998244353;
		}
		cout << ans << endl;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41046771/article/details/87987635