← Home
#include <bits/stdc++.h>
using namespace std;
 
using int64 = long long;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    int64 x, y;
    if (!(cin >> n >> x >> y)) return 0;
    vector<int> a(n);
    int maxA = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        maxA = max(maxA, a[i]);
    }
 
    // gcd of whole array
    int g = 0;
    for (int v : a) g = std::gcd(g, v);
    if (g != 1) {
        cout << 0 << '\n';
        return 0;
    }
 
    const int LIMIT = 2000000;          // see analysis
    vector<int> cnt(LIMIT + 1, 0);
    for (int v : a) ++cnt[v];
 
    // prefix sums
    vector<int64> prefCnt(LIMIT + 1, 0), prefSum(LIMIT + 1, 0);
    for (int i = 0; i <= LIMIT; ++i) {
        prefCnt[i] = cnt[i] + (i ? prefCnt[i - 1] : 0);
        prefSum[i] = (int64)cnt[i] * i + (i ? prefSum[i - 1] : 0);
    }
 
    int64 answer = (int64)n * x;               // delete everything
 
    // sieve primes up to LIMIT
    vector<int> primes;
    vector<bool> isComp(LIMIT + 1, false);
    for (int i = 2; i <= LIMIT; ++i) {
        if (!isComp[i]) {
            primes.push_back(i);
            if ((int64)i * i <= LIMIT)
                for (int j = i * i; j <= LIMIT; j += i)
                    isComp[j] = true;
        }
    }
 
    int64 K = x / y;            // maximal useful increase
 
    for (int p : primes) {
        int64 total = 0;
        for (int L = 0; L <= LIMIT; L += p) {
            int R = min(L + p - 1, LIMIT);
            int64 cntAll = prefCnt[R] - (L ? prefCnt[L - 1] : 0);
            int64 cntZero = (L <= LIMIT ? cnt[L] : 0);   // already a multiple
 
            int incL = max(L + 1, R - (int)K + 1);
            if (incL <= R) {
                int64 cntInc = prefCnt[R] - prefCnt[incL - 1];
                int64 sumInc = prefSum[R] - prefSum[incL - 1];
                int64 deltaSum = (int64)(R + 1) * cntInc - sumInc;
                total += deltaSum * y;
                int64 cntDel = cntAll - cntZero - cntInc;
                total += cntDel * x;
            } else {
                int64 cntDel = cntAll - cntZero;
                total += cntDel * x;
            }
            if (total >= answer) break;   // early stop, not better
        }
        answer = min(answer, total);
    }
 
    cout << answer << '\n';
    return 0;
}