题解
2024-09-11 14:30:57
发布于:江苏
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
struct Nums{
int prime;
int cnt;
}p[maxn];
int a[maxn];
int m1, m2;
int n;
int total = 0;
void div(int num){
if (num == 1){
return ;
}
for (int i = 2; i * i <= num; i){
if (num % i == 0){
p[total].prime = i;
while (num % i == 0){
num /= i;
p[total].cnt;
}
p[total].cnt *= m2;
}
}
if(num != 1){
p[total].prime = num;
p[total].cnt = m2;
}
return ;
}
bool check(int x){
for (int i = 1; i <= total; i){
if (x % p[i].prime != 0){
return 0;
}
}
return true;
}
int minn = INT_MAX;
void cultivate(int x){
int maxx = 0;
for (int i = 1; i <= total; i){
int tmp = 0;
while (x % p[i].prime == 0){
tmp++;
x /= p[i].prime;
}
int ans = (p[i].cnt - 1) / tmp + 1;
maxx = max(maxx, ans);
}
minn = min(minn, maxx);
return ;
}
signed main(){
cin >> n;
cin >> m1 >> m2;
div(m1);
for (int i = 1; i <= n; i++){
cin >> a[i];
if (check(a[i]) == 0){
continue;
}
cultivate(a[i]);
}
if (minn == INT_MAX){
cout << -1;
}
else{
cout << minn ;
}
return 0;
}
这里空空如也
有帮助,赞一个