#include <bits/stdc++.h>
using namespace std;
const int N1 = (int)(1e6 + 0.5);
const long long N2 = (long long)(1e12 + 0.5);
struct emt {
  long long a, cost;
};
bool cmp(emt u, emt v) { return u.cost < v.cost; }
emt e[N1 + 5];
unordered_map<long long, int> CNT;
long long gcd(long long x, long long y) { return !x ? y : gcd(y % x, x); }
vector<long long> decomdd;
int prime_decomp_dd(long long x) {
  for (int y = 2; y <= N1; y++) {
    if (x % y) continue;
    decomdd.push_back(y);
    while (x % y == 0) x /= y;
  }
  if (x > 1) decomdd.push_back(x);
  return decomdd.size();
}
long long prime_decomp_a(long long x) {
  long long t = 1;
  for (long long y : decomdd)
    while (x % y == 0) x /= y, t *= y;
  return t;
}
long long dp[12][1 << 11], dp1[12][1 << 11];
void work(int S, long long cost, int LEN) {
  for (int i = 1; i <= LEN; i++) {
    for (int j = 0; j < (1 << LEN); j++)
      dp[i][j | S] = min(dp[i][j | S], dp1[i - 1][j] + cost);
  }
}
int used[1 << 11];
int main() {
  int n;
  long long K, dd = 0;
  cin >> n >> K;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &e[i].a);
    dd = gcd(dd, e[i].a);
  }
  if (dd == 1) {
    puts("0");
    return 0;
  }
  int LEN = prime_decomp_dd(dd);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &e[i].cost);
    e[i].a = prime_decomp_a(e[i].a);
  }
  sort(e + 1, e + n + 1, cmp);
  memset(dp, 1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    if (++CNT[e[i].a] > LEN) continue;
    long long mul[11], prod[1 << 11];
    prod[0] = 1;
    for (int j = 0; j < LEN; j++) {
      mul[j] = 1;
      while (e[i].a % decomdd[j] == 0)
        e[i].a /= decomdd[j], mul[j] *= decomdd[j];
    }
    memcpy(dp1, dp, sizeof(dp1));
    for (int j = 0; j < LEN; j++) {
      for (int k = (1 << j); k < (1 << (j + 1)); k++) {
        prod[k] = prod[k ^ (1 << j)] * mul[j];
        if (prod[k] <= K && used[k]++ < LEN) work(k, e[i].cost, LEN);
      }
    }
  }
  long long ans = 1e13;
  for (int i = 1; i <= LEN; i++) ans = min(ans, dp[i][(1 << LEN) - 1] * i);
  if (ans >= 1e13) ans = -1;
  cout << ans << endl;
  return 0;
}
