#include //#include using namespace std; //using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; //using mint = modint998244353; vector calc(ll x){ vector ret(0); for(ll i = 1; i*i <= x; i++){ if(x % i == 0){ ret.push_back(i); if(i*i < x)ret.push_back(x/i); } } return ret; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll n,w; cin >> n >> w; vector x(n,0); vector y(n,0); for(ll i = 0; i < n; i++){ cin >> x[i]; } for(ll i = 0; i < n; i++){ cin >> y[i]; } unordered_map dp; vector> yaku(n,vector(0)); for(ll i = 0; i < n; i++){ yaku[i] = calc(x[i]); for(ll t : yaku[i]){ dp[t] += y[i]; } } ll ans = 0; for(ll i = w; i <= 200000; i++){ ans = max(ans,dp[i]); } cout << ans << '\n'; }