#include <bits/stdc++.h>
using namespace std;
const int summax = 45;
const int nmax = (1 << 12) + 5;
const int prmax = 12;
const long long inf = 1LL * 1e15;
map<long long, int> m;
map<long long, int>::iterator it;
vector<int> l[1000 * 1000 + 5];
long long k;
long long v[1000 * 1000 + 5], e[1000 * 1000 + 5];
long long prod[nmax];
long long cost[20][nmax], ce[1000 * 1000 + 5];
long long dp[20][nmax];
long long cat[20], pr[20], pu[20];
long long sum[40];
bool bun[nmax];
long long x, pret, act, mn;
int n, i, nr, j, lev, masti, wh, rel, b, oldlev;
void dyn(long long x, long long pret) {
  for (lev = nr; lev >= 1; lev--) {
    for (i = 0; i < (1 << nr); i++)
      if (dp[lev - 1][i] != inf) {
        for (j = i; j != 0; j = ((j - 1) & i))
          if (bun[j])
            dp[lev][(i - j)] = min(dp[lev][(i - j)], dp[lev - 1][i] + pret);
      }
  }
}
void ins() {
  sort(l[wh].begin(), l[wh].end());
  rel = min(nr, (int)l[wh].size());
  for (i = 0; i < nr; i++) prod[(1 << i)] = cat[i + 1];
  prod[0] = 1;
  for (i = 1; i < (1 << nr); i++) {
    prod[i] = (1LL * prod[(i & (i - 1))] * prod[((i ^ (i - 1)) & i)]);
    bun[i] = (prod[i] <= k);
  }
  for (int it = 0; it < rel; it++) dyn(ce[wh], l[wh][it]);
}
long long gcd(long long A, long long B) {
  if ((!A) || (!B)) return (A + B);
  return gcd(B, A % B);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> v[i];
    x = gcd(x, v[i]);
  }
  for (long long p = 2; p <= 1000 * 1000; p++) {
    if (x % p == 0) {
      ++nr;
      pr[nr] = p;
      while (x % p == 0) {
        pu[nr]++;
        x /= p;
      }
    }
  }
  if (x != 1) {
    ++nr;
    pr[nr] = x;
    pu[nr] = 1;
  }
  for (i = 1; i <= n; i++) {
    act = 1;
    x = v[i];
    for (j = 1; j <= nr; j++) {
      while (x % pr[j] == 0) {
        act *= pr[j];
        x /= pr[j];
      }
    }
    v[i] = act;
    if (!m[v[i]]) {
      m[v[i]] = ++masti;
      ce[masti] = v[i];
    }
  }
  for (i = 1; i <= n; i++) {
    cin >> e[i];
    l[m[v[i]]].push_back(e[i]);
  }
  mn = inf;
  for (lev = 0; lev <= 12; lev++)
    for (i = 0; i < (1 << nr); i++) dp[lev][i] = inf;
  dp[0][(1 << nr) - 1] = 0;
  if (dp[0][0] == 0) mn = 0;
  for (wh = 1; wh <= masti; wh++) {
    x = ce[wh];
    for (j = 1; j <= nr; j++) {
      cat[j] = 1;
      while (x % pr[j] == 0) {
        cat[j] *= pr[j];
        x /= pr[j];
      }
    }
    ins();
  }
  for (long long lev = 1; lev <= nr; lev++) mn = min(mn, lev * dp[lev][0]);
  if (mn == inf)
    cout << "-1";
  else
    cout << mn;
  return 0;
}
