版权声明:请大家斧正,如喜欢的话,为拙见点一个赞吧。 https://blog.csdn.net/qq_39897867/article/details/82947599
题目
Description
有n个正整数a[i],设它们乘积为p,你可以给p乘上一个正整数q,使p*q刚好为正整数m的阶乘,求m的最小值。
Input
共两行。
第一行一个正整数n。
第二行n个正整数a[i]。
Output
共一行
一个正整数m。
解题思路
题目要求一个最小的
使
包含
这个因子。
可以把p分解质因数,假设
(
为质数),那么只要
包含了每个
,
就包含
。
所以对于每个
,分别求出满足条件的最小的
,取最大值即可。
代码
#include<cstdio>
#include<algorithm>
using namespace std;
int n,b,cnt[200501];
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&b);
for (int j=2;j*j<=b;j++)
while (b%j==0)
{
cnt[j]++; b/=j;
}
if (b>1) cnt[b]++;
}
long long cur=0,maxn=0;
for (int i=2;i<=200000;i++)
if (cnt[i]>0)
{
cur=i;
while (cnt[i]>0)
{
long long tmp=cur;
while (tmp%i==0) cnt[i]--,tmp/=i;
cur=cur+i;
}
maxn=max(maxn,cur-i);
}
printf("%lld",maxn);
}