#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9 + 1e6 + 123);
const long long LINF = (long long)(1e18 + 1e9 + 123);
const long long MOD = (long long)(1e9 + 7);
template <typename A, typename B>
void mini(A& x, const B& y) {
  if (y < x) {
    x = y;
  }
}
void run();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  run();
  return 0;
}
long long gcd(long long x, long long y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
int n;
long long k;
vector<long long> a;
vector<long long> e;
bool test(int mask, int bit) { return mask & (1 << bit); }
void run() {
  cin >> n >> k;
  a.resize(n);
  for (long long& x : a) {
    cin >> x;
  }
  e.resize(n);
  for (long long& x : e) {
    cin >> x;
  }
  long long g = 0;
  for (long long x : a) {
    g = gcd(g, x);
  }
  if (g == 1) {
    cout << "0\n";
    return;
  }
  vector<long long> just;
  vector<long long> primes;
  for (long long d = 2; d * d <= g; d++) {
    if (g % d != 0) {
      continue;
    }
    long long t = 1;
    while (g % d == 0) {
      t *= d;
      g /= d;
    }
    primes.push_back(t);
    just.push_back(t);
  }
  if (g > 1) {
    primes.push_back(g);
    just.push_back(g);
  }
  int m = (int)primes.size();
  auto check = [m](int mask, const vector<long long>& p) {
    long long res = 1;
    for (int i = 0; i < m; i++) {
      if (test(mask, i)) {
        res *= p[i];
      }
    }
    return res <= k;
  };
  map<vector<long long>, vector<long long>> wow;
  for (int i = 0; i < n; i++) {
    vector<long long> cur(m);
    long long x = a[i];
    for (int j = 0; j < m; j++) {
      cur[j] = 1;
      while (x % just[j] == 0) {
        x /= just[j];
        cur[j] *= just[j];
      }
    }
    wow[cur].push_back(e[i]);
  }
  vector<bool> ok(1 << m);
  vector<vector<long long>> dp(1 << m, vector<long long>(m + 1, LINF));
  dp[0][0] = 0;
  for (auto& it : wow) {
    vector<long long>& costs = it.second;
    sort(costs.begin(), costs.end());
    while ((int)costs.size() > m) {
      costs.pop_back();
    }
    for (int mask = 0; mask < (1 << m); mask++) {
      ok[mask] = check(mask, it.first);
    }
    for (int c : costs) {
      for (int mask = (1 << m) - 1; mask > 0; mask--) {
        for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {
          if (!ok[submask]) {
            continue;
          }
          for (int cnt = 1; cnt <= m; cnt++) {
            mini(dp[mask][cnt], dp[mask ^ submask][cnt - 1] + c);
          }
        }
      }
    }
  }
  long long ans = LINF;
  for (int take = 1; take <= m; take++) {
    long long x = dp[(1 << m) - 1][take];
    if (x != LINF) {
      mini(ans, x * take);
    }
  }
  cout << (ans == LINF ? -1 : ans) << "\n";
}
