#include <bits/stdc++.h>
using namespace std;
const int N = 1000003, M = 1 << 11;
const long long INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) return a = b, 1;
  return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int n, m, lim, e[N];
long long k, g, a[N], pr[11], f[12][M], ans = INF;
map<long long, vector<int> > ma;
bool ok[M];
int main() {
  read(n);
  read(k);
  memset(f, 0x3f, sizeof f);
  for (int i = 0; i < n; ++i) {
    read(a[i]);
    g = gcd(a[i], g);
  }
  for (long long i = 2; i * i <= g; ++i)
    if (!(g % i)) {
      if (i > k) return puts("-1"), 0;
      pr[m++] = i;
      do g /= i;
      while (!(g % i));
    }
  if (g > k) return puts("-1"), 0;
  if (g > 1) pr[m++] = g;
  lim = 1 << m;
  for (int i = 0; i < n; ++i) {
    long long tmp = 1;
    read(e[i]);
    for (int j = 0; j < m; ++j)
      while (!(a[i] % pr[j])) {
        a[i] /= pr[j];
        tmp *= pr[j];
      }
    ma[tmp].emplace_back(e[i]);
  }
  f[0][0] = 0;
  for (auto _ : ma) {
    long long x = _.first;
    sort((_.second).begin(), (_.second).end());
    if (_.second.size() > m) _.second.resize(m);
    for (int S = 0; S < lim; ++S) {
      long long tmp = x, res = 1;
      for (int i = 0; i < m; ++i)
        if (S >> i & 1)
          while (!(tmp % pr[i])) {
            tmp /= pr[i];
            res *= pr[i];
          }
      ok[S] = res <= k;
    }
    for (int val : _.second) {
      bool flg = true;
      for (int i = m - 1; ~i; --i)
        for (int S = 0; S < lim; ++S)
          if (f[i][S] < INF)
            for (int T = S | (S + 1); T < lim; T = S | (T + 1))
              if (ok[S ^ T] && chmin(f[i + 1][T], f[i][S] + val)) flg = false;
      if (flg) break;
    }
  }
  for (int i = 0; i <= m; ++i)
    if (f[i][lim - 1] < INF) chmin(ans, f[i][lim - 1] * i);
  printf("%lld\n", ans == INF ? -1 : ans);
}
