#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
long long a[1000035], e[1000035], res;
vector<long long> ps;
map<long long, vector<long long>> mp;
long long dp[1 << 13][12];
void init() {
  long long x = res;
  for (long long d = 2; d * d <= x; d++)
    if (x % d == 0) {
      ps.push_back(d);
      while (x % d == 0) x /= d;
    }
  if (x > 1) ps.push_back(x);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    long long x = a[i];
    for (long long p : ps)
      while (x % p == 0) x /= p;
    long long t = a[i] / x;
    mp[t].push_back(e[i]);
  }
  m = ps.size();
  for (int(i) = 0; (i) < (int)(1 << m); (i)++)
    for (int(j) = 0; (j) < (int)(m + 1); (j)++) dp[i][j] = (1LL << 60);
  dp[0][0] = 0;
  int all = (1 << m) - 1;
  for (auto& p : mp) {
    sort(p.second.begin(), p.second.end());
    int N = p.second.size();
    mintt(N, m);
    vector<long long> vp(1 << m, 0);
    for (int(i) = 0; (i) < (int)(1 << m); (i)++) {
      long long t = 1, x = p.first;
      for (int(j) = 0; (j) < (int)(m); (j)++)
        if (i & (1 << j)) {
          while (x % ps[j] == 0) {
            x /= ps[j];
            t *= ps[j];
          }
        }
      vp[i] = t;
    }
    for (int(z) = 0; (z) < (int)(N); (z)++) {
      long long val = p.second[z];
      for (int j = m - 1; ~j; j--) {
        for (int s = 0; s < (1 << m); s++)
          if (dp[s][j] < (1LL << 60)) {
            int fan = all - s;
            for (int tmp = fan; tmp != 0; tmp = (tmp - 1) & fan) {
              if (vp[tmp] <= lk) {
                mintt(dp[s | tmp][j + 1], dp[s][j] + val);
              }
            }
          }
      }
    }
  }
  long long ans = (1LL << 60);
  for (int(j) = 0; (j) < (int)(m + 1); (j)++)
    if (dp[all][j] < (1LL << 60)) mintt(ans, dp[all][j] * j);
  if (ans == (1LL << 60)) ans = -1;
  printf("%lld\n", ans);
}
void fmain(int tid) {
  scanf("%d%lld", &n, &lk);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%lld", a + i);
    res = gcd1(res, a[i]);
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%lld", e + i);
  if (res == 1) {
    puts("0");
    return;
  }
  init();
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
