对新手特别友好
2026-05-27 13:13:36
发布于:广东
5阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> factor(int x) {
vector<pair<int, int>> res;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
int cnt = 0;
while (x % i == 0) {
cnt++;
x /= i;
}
res.emplace_back(i, cnt);
}
}
if (x > 1) res.emplace_back(x, 1);
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, m1, m2;
cin >> N >> m1 >> m2;
if (m1 == 1) {
cout << 0 << endl;
return 0;
}
auto m_fac = factor(m1);
for (auto& p : m_fac) p.second *= m2;
int min_time = INT_MAX;
while (N--) {
long long s;
cin >> s;
auto s_fac = factor((int)s);
bool ok = true;
int max_t = 0;
for (auto [p, need] : m_fac) {
int have = 0;
for (auto [q, cnt] : s_fac) {
if (q == p) {
have = cnt;
break;
}
}
if (have == 0) {
ok = false;
break;
}
int t = (need + have - 1) / have;
if (t > max_t) max_t = t;
}
if (ok && max_t < min_time) {
min_time = max_t;
}
}
if (min_time == INT_MAX) cout << -1 << endl;
else cout << min_time << endl;
return 0;
}

全部评论 1
嗯
1周前 来自 福建
0












有帮助,赞一个