题解
2023-03-04 17:46:52
发布于:上海
#include <bits/stdc++.h>
using namespace std;
int n,m1,m2,ans = 150000;
int i,j;
int s[10001],f[10001];
bool p[30001];
int prime[501][3],size = 0;
int main(void)
{
memset(p,1,sizeof(p));
memset(f,0,sizeof(f));
scanf("%d%d%d",&n,&m1,&m2);
if (m1 == 1)
{
printf("0");
return 0;
}
for (i = 1; i <= n; i++)
scanf("%d",&s[i]);
int xx = floor(sqrt(m1));
for (i = 2; i <= xx; i++)
{
if (p[i])
{
if (m1 % i == 0)
{
prime[size][1] = i;
prime[size][2] = 1;
}
}
int tim = 2;
while (tim * i <= m1)
{
p[tim * i] = 0;
tim;
}
}
for (i = 1; i <= size; i++)
{
int num = prime[i][1];
while (m1 % (num * prime[i][1]) == 0)
{
num *= prime[i][1];
prime[i][2];
}
prime[i][2] *= m2;
}
if (size == 0)
{
prime[size][1] = m1;
prime[size][2] = m2;
}
for (i = 1; i <= n; i)
{
for (j = 1; j <= size; j)
{
if (s[i] % prime[j][1] != 0)
{
f[i] = 150000;
break;
}
int tim = 1;
long long num = prime[j][1];
while (s[i] % (num * prime[j][1]) == 0)
{
num *= prime[j][1];
tim++;
}
int an = (prime[j][2]-1) / tim + 1;
if (an > f[i]) f[i] = an;
}
}
for (i = 1; i <= n; i++)
if (ans > f[i]) ans=f[i];
if (ans == 150000) printf("-1");
else printf("%d",ans);
return 0;
}
全部评论 5
法姐,请受徒儿一拜(看过法姐多项评论)
2024-03-03 来自 浙江
1我勒个豆
2024-03-13 来自 上海
1听网上说您不是离开了吗?
2024-03-14 来自 浙江
0别咒法姐
2024-06-08 来自 广东
0
厉害
2024-10-11 来自 甘肃
0法姐!!!你太牛掰!!!(看过法姐多项评论){话说法姐是不是CH圈的呀...}
2024-08-25 来自 广东
0#include <bits/stdc++.h>
using namespace std;
int n,m1,m2,ans = 150000;
int i,j;
int s[10001],f[10001];
bool p[30001];
int prime[501][3],size = 0;
int main(void)
{
memset(p,1,sizeof(p));
mems2024-04-27 来自 北京
0法姐,请问有什么自学c++的书推荐吗?
2023-08-10 来自 广东
0c++Primer
2023-08-10 来自 上海
0
有帮助,赞一个