#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
const long long INF = (long long)1e16;
const int N = (int)1e6 + 55;
const int K = 11;
const int M = (1 << K) + 5;
int n;
pair<long long, long long> a[N];
long long e[K];
long long d[M];
int m;
long long p[K];
long long r[N];
vector<pair<long long, int> > c[N];
int ID;
long long dp[K + 1][M];
pair<long long, int> trans[M][K];
vector<int> trans2[N];
long long k;
void addTrans(int mask, pair<long long, int> w) {
  for (int i = 0; i < m; i++) {
    if (w < trans[mask][i]) swap(w, trans[mask][i]);
  }
}
int main() {
  scanf("%d%lld", &n, &k);
  long long X = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i].first);
    X = gcd(X, a[i].first);
  }
  for (int i = 0; i < n; i++) scanf("%lld", &a[i].second);
  for (long long x = 2; x * x <= X; x++) {
    if (X % x) continue;
    p[m++] = x;
    while (X % x == 0) X /= x;
  }
  if (X > 1) {
    p[m++] = X;
  }
  for (int mask = 0; mask < (1 << m); mask++)
    for (int i = 0; i <= m; i++) dp[i][mask] = INF;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    long long x = a[i].first, y = 1;
    for (int j = 0; j < m; j++) {
      while (x % p[j] == 0) {
        x /= p[j];
        y *= p[j];
      }
    }
    a[i].first = y;
  }
  sort(a, a + n);
  ID = -1;
  for (int i = 0; i < n; i++) {
    if (i == 0 || a[i].first != a[i - 1].first) {
      ID++;
      r[ID] = a[i].first;
    }
    c[ID].push_back(make_pair(a[i].second, i));
  }
  ID++;
  for (int mask = 0; mask < (1 << m); mask++)
    for (int i = 0; i < m; i++) trans[mask][i] = make_pair(INF, -1);
  for (int it = 0; it < ID; it++) {
    while ((int)c[it].size() > m) c[it].pop_back();
    long long x = r[it];
    for (int i = 0; i < m; i++) {
      e[i] = 1;
      while (x % p[i] == 0) {
        e[i] *= p[i];
        x /= p[i];
      }
    }
    d[0] = 1;
    for (int mask = 1; mask < (1 << m); mask++) {
      int pos = 0;
      while (((mask >> pos) & 1) == 0) pos++;
      d[mask] = d[mask ^ (1 << pos)] * e[pos];
      if (d[mask] <= k) {
        for (int i = 0; i < (int)c[it].size(); i++) {
          addTrans(mask, c[it][i]);
        }
      }
    }
  }
  for (int mask = 0; mask < (1 << m); mask++)
    for (int i = 0; i < m; i++)
      if (trans[mask][i].second != -1) {
        trans2[trans[mask][i].second].push_back(mask);
      }
  for (int i = 0; i < n; i++) {
    if (trans2[i].empty()) continue;
    for (int s = m; s > 0; s--)
      for (int nmask : trans2[i]) {
        int all = (1 << m) - 1 - nmask;
        for (int mask = all;; mask = (mask - 1) & all) {
          dp[s][mask ^ nmask] =
              min(dp[s][mask ^ nmask], dp[s - 1][mask] + a[i].second);
          if (mask == 0) break;
        }
      }
  }
  long long ans = INF;
  for (int i = 0; i <= m; i++)
    if (dp[i][(1 << m) - 1] < INF) ans = min(ans, i * dp[i][(1 << m) - 1]);
  if (ans == INF)
    printf("-1\n");
  else
    printf("%lld\n", ans);
  return 0;
}
