#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 5;
const int M = 2048;
int n;
long long kk, gcdd;
pair<long long, int> juds[N];
int sp[20];
vector<int> msk[M], nmsk[M];
int cnt[M];
void init();
int actv_num;
vector<int> actv_conf[14];
bool dp_flg[M][14];
long long dp_res[M][14];
vector<long long> fac;
set<int> candi_maxl_v;
vector<int> maxl_v;
long long gcd_fac[20], jud_fac[20];
int main() {
  init();
  int i, j, k, a, b, c;
  long long cur_tmp, rem;
  k = sp[fac.size()];
  for (i = 0; i < k; i++) {
    cur_tmp = kk;
    for (auto s : msk[i]) cur_tmp /= gcd_fac[s];
    if (!cur_tmp) continue;
    candi_maxl_v.insert(i);
  }
  actv_num = 0;
  actv_conf[0].push_back(0);
  dp_flg[0][0] = true;
  dp_res[0][0] = 0LL;
  for (i = 0; i < n; i++) {
    if (!candi_maxl_v.size()) continue;
    maxl_v.clear();
    juds[i].first /= gcdd;
    for (j = 0; j < fac.size(); j++) {
      jud_fac[j] = gcd_fac[j];
      while (juds[i].first % fac[j] == 0)
        juds[i].first /= fac[j], jud_fac[j] *= fac[j];
    }
    auto it = candi_maxl_v.begin();
    while (it != candi_maxl_v.end()) {
      auto rit = it++;
      auto ss = *rit;
      rem = kk;
      for (auto s : msk[ss]) rem /= jud_fac[s];
      if (!rem) continue;
      if (++cnt[ss] >= fac.size()) candi_maxl_v.erase(rit);
      for (j = 0; j < nmsk[ss].size(); j++)
        if (jud_fac[nmsk[ss][j]] <= rem) break;
      if (j < nmsk[ss].size()) continue;
      maxl_v.push_back(ss);
    }
    if (!maxl_v.size()) continue;
    for (a = actv_num; a >= 0; a--) {
      for (auto t : actv_conf[a]) {
        for (auto s : maxl_v) {
          if ((s & t) == s) continue;
          k = (s | t);
          j = a + 1;
          cur_tmp = dp_res[t][a] + juds[i].second;
          if (j > actv_num) actv_num = j;
          if (!dp_flg[k][j]) {
            actv_conf[j].push_back(k);
            dp_flg[k][j] = true;
            dp_res[k][j] = cur_tmp;
          } else if (cur_tmp < dp_res[k][j])
            dp_res[k][j] = cur_tmp;
        }
      }
    }
  }
  int goal = sp[fac.size()] - 1;
  long long cur_min = LLONG_MAX;
  if (!goal) cur_min = 0LL;
  for (i = 0; i <= fac.size(); i++)
    if (dp_flg[goal][i] && 1LL * i * dp_res[goal][i] < cur_min)
      cur_min = 1LL * i * dp_res[goal][i];
  if (cur_min < LLONG_MAX)
    printf("%I64d\n", cur_min);
  else
    printf("-1\n");
  return 0;
}
inline long long gcd(long long a, long long b) {
  long long ttr;
  while (b) ttr = a % b, a = b, b = ttr;
  return a;
}
struct ooi_ioo {
  static const int _buf_size = 1 << 25;
  char buf[_buf_size], *_pos = buf;
  ooi_ioo() { fread(buf, 1, _buf_size, stdin); }
  ooi_ioo &operator>>(long long &res) {
    while (!isdigit(*_pos)) _pos++;
    res = *_pos++ & 15;
    while (isdigit(*_pos)) (res *= 10) += *_pos++ & 15;
    return *this;
  }
} oi_io;
bool comp(const pair<long long, long long> &a,
          const pair<long long, long long> &b) {
  return a.second < b.second;
}
void init() {
  int i, j, k;
  long long tmp;
  for (i = 0; i < 20; i++) sp[i] = 1 << i;
  oi_io >> tmp >> kk;
  n = tmp;
  oi_io >> juds[0].first;
  gcdd = juds[0].first;
  for (i = 1; i < n; i++) {
    oi_io >> juds[i].first;
    gcdd = gcd(gcdd, juds[i].first);
  }
  for (i = 0; i < n; i++) oi_io >> tmp, juds[i].second = tmp;
  sort(juds, juds + n, comp);
  tmp = gcdd;
  k = 0;
  for (long long ii = 2; ii * ii <= tmp; ii++) {
    if (tmp % ii == 0) {
      fac.push_back(ii);
      gcd_fac[k] = 1LL;
      while (tmp % ii == 0) tmp /= ii, gcd_fac[k] *= ii;
      k++;
    }
  }
  if (tmp > 1) {
    fac.push_back(tmp);
    gcd_fac[k++] = tmp;
  }
  k = sp[fac.size()];
  for (i = 0; i < k; i++) {
    for (j = 0; j < fac.size(); j++) {
      if (i & sp[j])
        msk[i].push_back(j);
      else
        nmsk[i].push_back(j);
    }
  }
}
