#include <bits/stdc++.h>
using namespace std;
long long get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    long long s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
    return -s;
  }
  long long s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s;
}
const int N = 2e6 + 5;
const int L = (1 << 11) + 5;
const long long INF = 1e18;
int n;
long long a[N];
long long k, g;
int e[N];
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
long long pri[100], pdt[100];
int u;
long long key[N];
int m;
map<long long, int> id;
long long pv[100];
int all[200000][15];
int pos[L][15];
void push(int *a, int x) {
  int w = a[0] + 1;
  for (int i = 1; i <= a[0]; i++)
    if (e[x] < e[a[i]]) {
      w = i;
      break;
    }
  for (int i = a[0] + 1; i >= w + 1; i--) a[i] = a[i - 1];
  a[w] = x;
  a[0] = min(a[0] + 1, u);
}
long long f[L][15], p[L][15];
int vis[L], tim;
int que[L], ta;
set<int> st[N];
int main() {
  n = get();
  k = get();
  for (int i = 1; i <= n; i++) a[i] = get();
  for (int i = 1; i <= n; i++) e[i] = get();
  g = a[1];
  for (int i = 2; i <= n; i++) g = gcd(g, a[i]);
  if (g == 1) return printf("0\n"), 0;
  u = 0;
  long long x = g, lim = sqrt(g);
  for (int i = 2; i <= lim; i++)
    if (x % i == 0) {
      pri[++u] = i;
      pdt[u] = 1;
      for (; x % i == 0; x /= i, pdt[u] *= i)
        ;
    }
  if (x > 1) {
    u++;
    pri[u] = pdt[u] = x;
  }
  for (int i = 1; i <= n; i++) {
    long long r = a[i], x = 1;
    for (long long d = gcd(r, g); d > 1; d = gcd(r, g)) r /= d, x *= d;
    if (!id[x]) key[id[x] = ++m] = x;
    push(all[id[x]], i);
  }
  for (int w = 1; w <= m; w++) {
    long long x = key[w];
    for (int i = 1; i <= u; i++) {
      pv[i] = 1;
      for (; x % pri[i] == 0;) x /= pri[i], pv[i] *= pri[i];
    }
    for (int s = 0; s <= (1 << u) - 1; s++) {
      long long v = 1;
      for (int i = 1; i <= u; i++)
        if ((s & (1 << (i - 1))) > 0) v *= pv[i];
      if (v <= k) {
        for (int x = 1; x <= all[w][0]; x++) push(pos[s], all[w][x]);
      }
    }
  }
  for (int s = 0; s <= (1 << u) - 1; s++)
    for (int i = 1; i <= pos[s][0]; i++) st[pos[s][i]].insert(s);
  for (int s = 0; s <= (1 << u) - 1; s++)
    for (int i = 0; i <= u; i++) f[s][i] = INF;
  f[0][0] = 0;
  for (int x = 1; x <= n; x++)
    if (st[x].begin() != st[x].end()) {
      tim++;
      ta = 0;
      for (set<int>::iterator h = st[x].begin(); h != st[x].end(); h++) {
        int s = (*h);
        int res = ((1 << u) - 1) ^ s;
        for (int t = 0;; t = ((t ^ s) + 1) & res) {
          if (vis[t ^ s] < tim) {
            vis[que[++ta] = t ^ s] = tim;
            for (int i = 0; i <= u; i++) p[t ^ s][i] = INF;
          }
          for (int i = 0; i <= u - 1; i++)
            if (f[t][i] < INF)
              p[t ^ s][i + 1] = min(p[t ^ s][i + 1], f[t][i] + e[x]);
          if (t == res) break;
        }
      }
      for (int w = 1; w <= ta; w++) {
        int s = que[w];
        for (int i = 0; i <= u; i++) f[s][i] = min(f[s][i], p[s][i]);
      }
    }
  long long ans = INF;
  for (int i = 0; i <= u; i++)
    if (f[(1 << u) - 1][i] < INF) ans = min(ans, f[(1 << u) - 1][i] * i);
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}
