#include #include #include #include #include using namespace std; typedef long long ll; ll c[5010]; int main(){ ll i,n,m,a,b; cin >> n >> m >> a >> b; for(i=0;i> c[i]; sort(c,c + m); map mp; set s; mp[1] = 0; s.insert(1); while(s.size()){ ll x = *s.begin(); s.erase(x); ll nn = n/x; ll val = mp[x]; vector d1,d2; for(i=1;i*i<=nn;i++){ if(nn%i==0){ if(i!=1) d1.push_back(i); if(i*i!=nn) d2.push_back(nn/i); } } reverse(d2.begin(),d2.end()); d1.insert(d1.end(),d2.begin(),d2.end()); int j = 0; for(i=0;i=x && c[j]%x==0) f = true; j++; } if(f) break; s.insert(now); //if(now==6) cout << d1[i] << " vvv " << val << " " << x << endl; if(mp.find(now)==mp.end()) mp[now] = val + (ll)(d1[i] - 1)*a + b; else mp[now] = min(mp[now],val + (ll)(d1[i] - 1)*a + b); } } if(mp.find(n)==mp.end()) cout << -1 << "\n"; else cout << mp[n] - b << "\n"; //for(auto x:mp) cout << x.first << " " << x.second << "\n"; }