#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T Tmin(const T &lch, const T &rch) {
  if (lch < rch) return lch;
  return rch;
}
template <class T>
inline T Tmax(const T &lch, const T &rch) {
  if (lch < rch) return rch;
  return lch;
}
template <class T>
inline T Tabs(const T &ch) {
  if (ch < 0) return -ch;
  return ch;
}
const long long LLInf = 10000000000000000LL;
const double Pi = acos(-1.0);
const int Inf = 0x3f3f3f3f;
const int Mod = 998244353;
const unsigned long long Big_Mod = 1e9 + 9;
const unsigned long long Rp = 13;
const unsigned long long Mp = 17;
const int Gp = 3;
inline int R_int() {
  register int n = 0;
  register char ch = getchar();
  register bool I = false;
  while (ch < '0' || ch > '9') I = (ch == '-' ? 1 : 0), ch = getchar();
  while (ch >= '0' && ch <= '9')
    n = (n << 1) + (n << 3) + (ch ^ '0'), ch = getchar();
  return I ? -n : n;
}
inline int Add(int a, int b) {
  int ans = (a + b);
  ans = (ans >= Mod ? ans - Mod : ans);
  return ans;
}
inline int Mis(int a, int b) {
  int ans = a - b;
  ans = (ans < 0 ? ans + Mod : ans);
  return ans;
}
inline int Mul(int a, int b) { return a * 1ll * b % Mod; }
inline int Pow(int a, long long k) {
  int ans = 1;
  while (k) {
    if (k & 1) ans = Mul(ans, a);
    a = Mul(a, a);
    k = k >> 1;
  }
  return ans;
}
const int maxn = 1000000 + 3;
const int maxc = 13;
struct Node {
  long long a;
  int e;
  Node() {}
  inline bool operator<(const Node &ch) const { return e < ch.e; }
};
long long f[2][maxc][(1 << maxc) + 1];
int res[(1 << maxc) + 1];
long long rev[(1 << maxc) + 1];
long long Prime[maxn];
Node v[maxn];
int tot = 0;
int n, m;
long long k;
map<long long, int> M;
inline long long Gcd(long long a, long long b) {
  return b == 0 ? a : Gcd(b, a % b);
}
signed main() {
  n = R_int();
  scanf("%I64d", &k);
  for (int i = 1; i <= n; i++) scanf("%I64d", &v[i].a);
  for (int i = 1; i <= n; i++) v[i].e = R_int();
  long long d = v[1].a;
  for (int i = 2; i <= n; i++) d = Gcd(d, v[i].a);
  if (d == 1) {
    puts("0");
    return 0;
  }
  for (long long i = 2; i * i <= d; i++) {
    if (d % i == 0) {
      Prime[++tot] = i;
      while (d % i == 0) d /= i;
    }
  }
  if (d != 1) Prime[++tot] = d;
  sort(v + 1, v + n + 1);
  int ALL = (1 << tot) - 1, u = 0, r = 1;
  for (int i = 0; i <= tot; i++) {
    for (int j = 1; j <= ALL; j++) {
      f[u][i][j] = LLInf;
    }
  }
  rev[0] = 1;
  int m = tot;
  for (int i = 1; i <= n; i++) {
    long long sum = 1, w = v[i].a, cur = 1;
    for (int j = 1; j <= m; j++) {
      if (w % Prime[j] == 0) {
        cur = 1;
        while (w % Prime[j] == 0) {
          cur *= Prime[j];
          w /= Prime[j];
        }
        rev[1 << (j - 1)] = cur;
        sum *= cur;
      }
    }
    if (++M[sum] > m) continue;
    swap(u, r);
    memcpy(f[u], f[r], sizeof(f[u]));
    for (int s = 1; s <= ALL; s++) {
      int t = s & (-s);
      rev[s] = rev[t] * rev[s ^ t];
      if (rev[s] > k) continue;
      if (++res[s] > m) continue;
      int es = ALL ^ s;
      for (int c = 0; c < m; c++) {
        for (int h = es; h; h = (h - 1) & es)
          f[u][c + 1][s | h] = Tmin(f[u][c + 1][s | h], f[r][c][h] + v[i].e);
        f[u][c + 1][s] = Tmin(f[u][c + 1][s], v[i].e * 1ll);
      }
    }
  }
  long long ans = LLInf;
  for (int i = 1; i <= m; i++) {
    ans = Tmin(ans, f[u][i][ALL] * i);
  }
  if (ans == LLInf) ans = -1;
  printf("%I64d\n", ans);
  return 0;
}
