#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 1000100;
int n, m, S, c[N];
long long d, k, a[N], p[N], f[13][1 << 12], ans;
bool vis[1 << 12];
map<long long, vector<int> > mp;
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) d = gcd(a[i] = read(), d);
  for (int i = 1; i <= n; i++) c[i] = read();
  for (long long i = 2; i * i <= d; i++)
    if (d % i == 0) {
      p[m++] = i;
      while (d % i == 0) d /= i;
    }
  if (d > 1) p[m++] = d;
  S = (1 << m) - 1;
  for (int i = 1; i <= n; i++) {
    long long res = 1;
    for (int k = 0; k < m; k++)
      while (a[i] % p[k] == 0) a[i] /= p[k], res *= p[k];
    mp[res].push_back(c[i]);
  }
  for (int i = 0; i < 13; i++)
    for (int j = 0; j < (1 << 12); j++) f[i][j] = 1000000000000000000ll;
  f[0][0] = 0;
  for (auto pr : mp) {
    long long x = pr.first;
    auto v = pr.second;
    sort(v.begin(), v.end());
    if (v.size() > m) v.resize(m);
    for (int t = 0; t <= S; t++) {
      long long y = x;
      for (int i = 0; i < m; i++)
        if (t & (1 << i))
          while (y % p[i] == 0) y /= p[i];
      vis[t] = (x / y <= k);
    }
    for (int cost : v) {
      bool fl = 0;
      for (int i = m - 1; ~i; i--)
        for (int j = 0; j <= S; j++)
          if (f[i][j] < 1000000000000000000ll)
            for (int k = (j + 1) | j; k <= S; k = (k + 1) | j)
              if (vis[k ^ j])
                if (f[i + 1][k] > f[i][j] + cost)
                  fl = 1, f[i + 1][k] = f[i][j] + cost;
      if (!fl) break;
    }
  }
  ans = 1000000000000000000ll;
  for (long long i = 0; i <= m; i++)
    if (f[i][S] < 1000000000000000000ll) ans = min(ans, i * f[i][S]);
  if (ans == 1000000000000000000ll)
    puts("-1");
  else
    print(ans), putchar('\n');
  return 0;
}
