#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &data) {
  data = 0;
  int w = 1;
  register char ch = 0;
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (isdigit(ch)) data = data * 10 + ch - '0', ch = getchar();
  data *= w;
}
const int MAX_N = 1e6 + 5;
const long long INF = 3e18;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int N, cnt;
long long K, G, a[MAX_N], e[MAX_N], p[MAX_N], f[13][1 << 13];
map<long long, vector<long long> > mp;
int main() {
  for (int i = 0; i < 13; i++)
    for (int s = 0; s < (1 << 13); s++) f[i][s] = INF;
  read(N), read(K);
  for (int i = 1; i <= N; i++) read(a[i]);
  for (int i = 1; i <= N; i++) read(e[i]);
  G = a[1];
  for (int i = 2; i <= N; i++) G = gcd(G, a[i]);
  for (long long i = 2ll; i * i <= G; i++) {
    if (G % i != 0) continue;
    p[cnt] = i;
    while (G % i == 0) G /= i;
    ++cnt;
  }
  if (G != 1ll) p[cnt] = G, ++cnt;
  for (int i = 1; i <= N; i++) {
    long long res = 1, tmp = a[i];
    for (int j = 0; j < cnt; j++)
      while (tmp % p[j] == 0) res *= p[j], tmp /= p[j];
    mp[res].push_back(e[i]);
  }
  f[0][0] = 0;
  for (map<long long, vector<long long> >::iterator ite = mp.begin();
       ite != mp.end(); ++ite) {
    long long x = ite->first;
    vector<int> vec;
    for (int i = 0; i < (1 << cnt); i++) {
      long long y = x, z = 1;
      for (int j = 0; j < cnt; j++)
        if ((i >> j) & 1)
          while (y % p[j] == 0) y /= p[j], z *= p[j];
      if (z <= K) vec.push_back(i);
    }
    sort(ite->second.begin(), ite->second.end());
    if ((int)ite->second.size() > cnt) ite->second.resize(cnt);
    for (vector<long long>::iterator it = ite->second.begin();
         it != ite->second.end(); ++it) {
      bool update = 0;
      for (int i = cnt - 1; ~i; i--) {
        for (vector<int>::iterator t = vec.begin(); t != vec.end(); ++t) {
          int tmp = ((1 << cnt) - 1) ^ *t;
          for (int j = tmp;; j = (j - 1) & tmp) {
            long long tt = f[i][j] + *it;
            if (tt < f[i + 1][*t ^ j]) f[i + 1][*t ^ j] = tt, update = 1;
            if (!j) break;
          }
        }
      }
      if (update == 0) break;
    }
  }
  long long ans = INF;
  for (int i = 0; i <= cnt; i++)
    if (f[i][(1 << cnt) - 1] != INF) ans = min(ans, f[i][(1 << cnt) - 1] * i);
  if (ans >= INF) ans = -1;
  cout << ans << endl;
  return 0;
}
