#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
void solve(__attribute__((unused)) bool);
void precalc();
clock_t start;
int main() {
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  int testNum = 1;
  while (t--) {
    solve(true);
  }
  cout.flush();
  return 0;
}
template <typename T>
T binpow(T q, T w, T mod) {
  if (!w) return 1 % mod;
  if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}
template <typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template <typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}
template <typename T>
void make_unique(vector<T>& a) {
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
}
template <typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}
template <typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}
void precalc() {}
long long dp[2][12][1 << 12];
void solve(__attribute__((unused)) bool read) {
  long long n, k;
  if (read) {
    cin >> n >> k;
  } else {
    n = 1e6;
    k = 1e12;
  }
  vector<long long> a(n), cost(n);
  long long g = 0;
  for (long long i = 0; i < n; ++i) {
    if (read) {
      cin >> a[i];
    } else {
      a[i] = 200560490130LL;
    }
    g = gcd(a[i], g);
  }
  for (long long i = 0; i < n; ++i) {
    if (read) {
      cin >> cost[i];
    } else {
      cost[i] = rand();
    }
  }
  vector<long long> primes;
  for (long long p = 2; p * p <= g; ++p) {
    if (g % p == 0) {
      primes.push_back(p);
      while (g % p == 0) {
        g /= p;
      }
    }
  }
  if (g > 1) {
    primes.push_back(g);
  }
  if (primes.empty()) {
    cout << "0\n";
    return;
  }
  vector<pair<long long, long long>> mapa;
  for (long long i = 0; i < n; ++i) {
    long long cur_val = 1;
    for (long long j = 0; j < primes.size(); ++j) {
      auto p = primes[j];
      while (a[i] % p == 0) {
        a[i] /= p;
        cur_val *= p;
      }
    }
    mapa.push_back({cur_val, cost[i]});
  }
  sort(mapa.begin(), mapa.end());
  vector<vector<long long>> vecs;
  vector<long long> costs;
  for (long long i = 0; i < mapa.size();) {
    long long j = i;
    vector<long long> vec;
    auto cur_val = mapa[i].first;
    vector<long long> key(primes.size(), 1);
    for (long long r = 0; r < primes.size(); ++r) {
      while (cur_val % primes[r] == 0) {
        cur_val /= primes[r];
        key[r] *= primes[r];
      }
    }
    while (j < mapa.size() && mapa[j].first == mapa[i].first) {
      vec.push_back(mapa[j].second);
      ++j;
    }
    i = j;
    long long enough_space = 0;
    long long cur_prod = 1;
    for (long long x : key) {
      if (x > k) {
        continue;
      }
      if (x * cur_prod <= k) {
        if (cur_prod == 1) {
          ++enough_space;
        }
        cur_prod *= x;
        continue;
      } else {
        ++enough_space;
        cur_prod = x;
      }
    }
    enough_space = primes.size();
    if (vec.size() > enough_space) {
      vec.resize(enough_space);
    }
    for (long long c : vec) {
      vecs.push_back(key);
      costs.push_back(c);
    }
  }
  const long long INF = (long long)1e18;
  long long full_mask = (1 << primes.size()) - 1;
  auto clear_dp = [&](long long par) {
    for (long long cnt = 0; cnt <= primes.size(); ++cnt) {
      for (long long mask = 0; mask <= full_mask; ++mask) {
        dp[par][cnt][mask] = INF;
      }
    }
  };
  long long par = 0;
  for (long long i = 0; i < 2; ++i) {
    clear_dp(i);
  }
  dp[par][0][full_mask] = 0;
  vector<long long> prods;
  for (long long i = 0; i < vecs.size(); ++i) {
    for (long long cnt = 0; cnt <= primes.size(); ++cnt) {
      for (long long mask = 0; mask <= full_mask; ++mask) {
        dp[par ^ 1][cnt][mask] = dp[par][cnt][mask];
      }
    }
    prods.assign(1 << primes.size(), 1);
    for (long long mask = 0; mask < (1 << primes.size()); ++mask) {
      for (long long j = 0; j < primes.size(); ++j) {
        if (mask & (1 << j)) {
          prods[mask] *= vecs[i][j];
        }
      }
    }
    for (long long cnt = 0; cnt <= primes.size(); ++cnt) {
      for (long long mask = 0; mask <= full_mask; ++mask) {
        long long cur_dp = dp[par][cnt][mask];
        if (cur_dp == INF) {
          continue;
        }
        for (long long s = mask; s > 0; s = (s - 1) & mask) {
          long long prod = prods[s];
          if (prod <= k) {
            relax_min(dp[par ^ 1][cnt + 1][mask ^ s], cur_dp + costs[i]);
          }
        }
      }
    }
    par ^= 1;
  }
  long long res = INF;
  for (long long cnt = 0; cnt <= primes.size(); ++cnt) {
    long long cur_dp = dp[par][cnt][0];
    if (cur_dp == INF) {
      continue;
    }
    relax_min(res, cnt * cur_dp);
  }
  if (res == INF) {
    res = -1;
  }
  cout << res << "\n";
}
