/** * @FileName a.cpp * @Author kanpurin * @Created 2022.08.13 10:03:51 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template struct Dijkstra { private: int V; struct edge { int to; T cost; }; vector> G; public: const T inf = numeric_limits::max(); vector d; Dijkstra() {} Dijkstra(int V) : V(V) { G.resize(V); } Dijkstra& operator=(const Dijkstra& obj) { this->V = obj.V; this->G = obj.G; this->d = obj.d; return *this; } void add_edge(int from, int to, T weight, bool directed = false) { G[from].push_back({to,weight}); if (!directed) G[to].push_back({from,weight}); } int add_vertex() { G.push_back(vector()); return V++; } void build(int s) { d.assign(V, inf); typedef tuple P; priority_queue, greater

> pq; d[s] = 0; pq.push(P(d[s], s)); while (!pq.empty()) { P p = pq.top(); pq.pop(); int v = get<1>(p); if (d[v] < get<0>(p)) continue; for (const edge &e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; pq.push(P(d[e.to], e.to)); } } } } }; template vector enum_div(T n) { vector ret; for (T i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.push_back(i); if (i * i != n) { ret.push_back(n / i); } } } return ret; } int main() { int n,m; ll a,b;cin >> n >> m >> a >> b; vector c(m); for (int i = 0; i < m; i++) { cin >> c[i]; } auto v = enum_div(n); sort(v.begin(), v.end()); vector d(v.size(),n+1); for (int i = 0; i < v.size(); i++) { for (int j = 0; j < m; j++) { if (c[j]%v[i]!=0) continue; d[i] = min(d[i],c[j]); } } Dijkstra g(v.size()); for (int i = 1; i < v.size(); i++) { if (d[0] <= v[i]) continue; g.add_edge(0,i,a*(v[i]-1),true); } for (int i = 1; i < v.size()-1; i++) { for (int j = i+1; j < v.size(); j++) { if (v[j] % v[i] != 0) continue; if (d[i] <= v[j]) continue; g.add_edge(i,j,a*(v[j]/v[i]-1)+b,true); } } g.build(0); if (g.d[v.size()-1] == g.inf) { cout << -1 << endl; } else { cout << g.d[v.size()-1] << endl; } return 0; }