萌新妹子在线求调
查看原帖
萌新妹子在线求调
1305692
xiangixuan楼主2025/1/15 20:45

WA30pts

#include <bits/stdc++.h>
#define N 20000001
using namespace std;
int n, m1, m2, s[N], ps[N], ks[N], pn[N], kn[N], ans = INT_MAX;
int divide(int n, int p[], int k[])
{
    int tot = 0;
    for (int i = 2; i * i <= n; ++i)
    {
        if (n % i != 0) continue;
        p[++tot] = i;
        while (n % i == 0)
            n /= i, ++k[tot];
    }
    if (n > 1)
    {
        p[++tot] = n;
        k[tot] = 1;
    }
    return tot;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m1 >> m2;
    for (int i = 1; i <= n; ++i)
        cin >> s[i];
    int tot = divide(m1, ps, ks);
    for (int i = 1; i <= tot; ++i)
        ks[i] *= m2;
    for (int i = 1; i <= n; ++i)
    {
        int cnt = divide(s[i], pn, kn);
        if (cnt < tot) continue;
        int tmp = 0, t = 1, h = 1;
        bool flag = 1;
        while (t <= tot)
        {
            if (ps[t] < ps[h] || h > cnt)
            {
                flag = 0;
                break;
            }
            if (ps[t] == pn[h])
            {
                tmp = max(tmp, (int)ceil((double)ks[t] / kn[h]));
                ++t, ++h;
            }
            else
                ++h;
        }
        if (flag)
            ans = min((int)ans, tmp);
    }
    if (ans != INT_MAX)
        cout << ans << '\n';
    else
        cout << "-1\n";
    return 0;
}
2025/1/15 20:45
加载中...