#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXP = 13;
long long DP[MAXP][1 << MAXP];
const long long INF = 1e16;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  ios_base::sync_with_stdio(0);
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<long long, long long>> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i].first;
  for (int i = 0; i < (N); ++i) cin >> A[i].second;
  long long g = A[0].first;
  for (int i = 0; i < (N); ++i) g = gcd(g, A[i].first);
  map<long long, vector<long long>> unc_to_experience;
  for (auto a : A) {
    long long r = 1, t;
    while ((t = gcd(a.first, g)) > 1) {
      a.first /= t;
      r *= t;
    }
    unc_to_experience[r].push_back(a.second);
  }
  vector<long long> primes;
  for (int i = (2); i < (1e6 + 5); ++i) {
    if (g % i == 0) {
      primes.push_back(i);
      while (g % i == 0) g /= i;
    }
  }
  if (g > 1) primes.push_back(g);
  int M = primes.size();
  assert(M < MAXP);
  for (int i = 0; i < (M + 1); ++i)
    for (int m = 0; m < (1 << M); ++m) DP[i][m] = INF;
  DP[0][0] = 0;
  for (auto p : unc_to_experience) {
    vector<long long> e = p.second;
    sort(e.begin(), e.end());
    for (int i = (1); i < (e.size()); ++i) e[i] += e[i - 1];
    vector<int> judges_required(1 << M, 1e7);
    judges_required[0] = 0;
    for (int m = 0; m < (1 << M); ++m) {
      long long D = 1;
      long long S = p.first;
      for (int k = 0; k < (M); ++k)
        if ((1 << k) & m)
          while (S % primes[k] == 0) {
            S /= primes[k];
            D *= primes[k];
          }
      if (D > K) continue;
      for (int m1 = (1 << M) - 1; m1 >= (0); --m1)
        if ((m & m1) == m)
          judges_required[m1] =
              min(judges_required[m1], judges_required[m1 - m] + 1);
    }
    for (int m1 = (1 << M) - 1; m1 >= (0); --m1)
      for (int m = (1); m < (1 << M); ++m)
        if ((m & m1) == m)
          if (judges_required[m] <= e.size())
            for (int i = (judges_required[m]); i < (M + 1); ++i)
              DP[i][m1] = min(DP[i][m1], DP[i - judges_required[m]][m1 - m] +
                                             e[judges_required[m] - 1]);
  }
  long long result = INF;
  for (int i = 0; i < (M + 1); ++i)
    if (DP[i][(1 << M) - 1] < INF) {
      result = min(result, i * DP[i][(1 << M) - 1]);
    }
  if (result < INF)
    cout << result << endl;
  else
    cout << -1 << endl;
}
