#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const long long maxn = 1000 * 1000 + 7, INF = 1e18 + 228;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
struct elem {
  long long a, e;
  elem() {}
  elem(long long _a, long long _e) {
    a = _a;
    e = _e;
  }
};
elem a[maxn];
bool operator<(elem fir, elem sec) { return fir.e < sec.e; }
vector<pair<vector<long long>, long long> > elems;
long long res = INF;
long long n, k, m;
long long msks[15];
vector<long long> g[15000], best[1 << 12];
long long mt[maxn];
bool used[15000];
bool cmp(long long i, long long j) { return elems[i].second < elems[j].second; }
bool dfs(long long v) {
  if (used[v]) return 0;
  used[v] = 1;
  for (long long to : g[v]) {
    if (mt[to] == -1) {
      mt[to] = v;
      return 1;
    }
  }
  for (long long to : g[v]) {
    if (dfs(mt[to])) {
      mt[to] = v;
      return 1;
    }
  }
  return 0;
}
long long it = 0;
long long use[maxn];
void gen(long long ptr) {
  ++it;
  if (it % 4096 == 0 && clock() > 2.95 * CLOCKS_PER_SEC) {
    if (res == INF)
      cout << -1 << '\n';
    else {
      cout << res << '\n';
    }
    exit(0);
  }
  if (ptr == m) {
    long long xx = 0;
    for (long long i = 0; i < m; ++i) {
      if (msks[i]) {
        ++xx;
      }
    }
    vector<long long> left228;
    for (long long i = 0; i < m; ++i) {
      for (long long j = 0; j < min(xx, (long long)best[msks[i]].size()); ++j) {
        g[best[msks[i]][j]].clear();
      }
    }
    for (long long i = 0; i < m; ++i) {
      if (msks[i]) {
        for (long long j = 0; j < min((long long)best[msks[i]].size(), xx);
             ++j) {
          g[best[msks[i]][j]].push_back(i);
          left228.push_back(best[msks[i]][j]);
        }
      }
    }
    sort(left228.begin(), left228.end());
    left228.erase(unique(left228.begin(), left228.end()), left228.end());
    sort(left228.begin(), left228.end(), cmp);
    for (long long i = 0; i < m; ++i) {
      mt[i] = -1;
    }
    long long cur_res = 0;
    long long pars = 0;
    for (long long j : left228) {
      used[j] = 0;
    }
    for (long long i : left228) {
      if (dfs(i)) {
        cur_res += elems[i].second;
        ++pars;
        for (long long j : left228) {
          used[j] = 0;
        }
      }
    }
    if (pars == xx) {
      uin(res, xx * cur_res);
    }
  } else {
    long long upper = ptr + 1;
    vector<long long> allowed;
    for (long long i = 0; i < m; ++i) {
      if (use[i]) {
        allowed.push_back(i);
      }
    }
    for (long long i = 0; i < m; ++i) {
      if (!use[i]) {
        allowed.push_back(i);
        break;
      }
    }
    for (long long i : allowed) {
      msks[i] += (1 << ptr);
      ++use[i];
      gen(ptr + 1);
      msks[i] -= (1 << ptr);
      --use[i];
    }
  }
}
long long cnta[1000 * 1000 + 7];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  long long G = 0;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i].a;
    G = gcd(G, a[i].a);
  }
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i].e;
  }
  sort(a + 1, a + n + 1);
  vector<long long> prs;
  long long i = 2;
  long long _G = G;
  while (i * i <= _G) {
    if (G % i == 0) {
      prs.push_back(i);
      while (G % i == 0) G /= i;
    }
    ++i;
  }
  if (G > 1) prs.push_back(G);
  m = (long long)prs.size();
  long long A = 0;
  vector<long long> maska(m);
  vector<vector<long long> > lol;
  for (long long i = 1; i <= n; ++i) {
    A = a[i].a;
    for (long long j = 0; j < m; ++j) {
      maska[j] = 0;
    }
    long long troy = 0;
    for (long long j = 0; j < m; ++j) {
      while (A % prs[j] == 0) A /= prs[j], ++maska[j];
      if (j < 3) {
        troy = troy * 67 + maska[j];
      } else {
        troy = troy * 13 + maska[j];
      }
    }
    troy %= (1000 * 1000 + 7);
    if (cnta[troy] < m) {
      ++cnta[troy];
      elems.push_back({maska, a[i].e});
      vector<long long> v(m, 1);
      for (long long j = 0; j < m; ++j) {
        for (long long it = 0; it < maska[j]; ++it) {
          v[j] *= prs[j];
        }
      }
      lol.push_back(v);
    }
  }
  for (long long mask = 0; mask < (1 << m); ++mask) {
    vector<long long> bits;
    for (long long j = 0; j < m; ++j) {
      if ((mask >> j) & 1) {
        bits.push_back(j);
      }
    }
    for (long long i = 0; i < (long long)elems.size(); ++i) {
      long long ch = 1;
      for (long long j : bits) {
        ch *= lol[i][j];
        if (ch > k) break;
      }
      if (ch <= k) {
        best[mask].push_back(i);
        if ((long long)best[mask].size() == m) {
          break;
        }
      }
    }
  }
  gen(0);
  if (res == INF)
    cout << -1 << '\n';
  else {
    cout << res << '\n';
  }
  return 0;
}
