#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll x, ll y) {
return y == 0 ? x : gcd(y, x % y);
}
const ll INF = (ll)1e16;
const int N = (int)1e6 + 55;
const int K = 11;
const int M = (1 << K) + 5;
int n;
pll a[N];
ll e[K];
ll d[M];
int m;
ll p[K];
ll r[N];
vector<pli> c[N];
int ID;
ll dp[K + 1][M];
pli trans[M][K];
vector<int> trans2[N];
ll k;
void addTrans(int mask, pli w) {
for (int i = 0; i < m; i++) {
if (w < trans[mask][i])
swap(w, trans[mask][i]);
}
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d%lld", &n, &k);
ll X = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i].first);
X = gcd(X, a[i].first);
}
for (int i = 0; i < n; i++)
scanf("%lld", &a[i].second);
for (ll x = 2; x * x <= X; x++) {
if (X % x) continue;
p[m++] = x;
while(X % x == 0) X /= x;
}
if (X > 1) {
p[m++] = X;
}
/*
cerr << m << endl;
for (int i = 0; i < m; i++)
cerr << p[i] << " ";
cerr << endl;
*/
for (int mask = 0; mask < (1 << m); mask++)
for (int i = 0; i <= m; i++)
dp[i][mask] = INF;
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
ll x = a[i].first, y = 1;
for (int j = 0; j < m; j++) {
while(x % p[j] == 0) {
x /= p[j];
y *= p[j];
}
}
a[i].first = y;
}
sort(a, a + n);
ID = -1;
for (int i = 0; i < n; i++) {
if (i == 0 || a[i].first != a[i - 1].first) {
ID++;
r[ID] = a[i].first;
}
c[ID].push_back(mp(a[i].second, i));
}
ID++;
for (int mask = 0; mask < (1 << m); mask++)
for (int i = 0; i < m; i++)
trans[mask][i] = mp(INF, -1);
for (int it = 0; it < ID; it++) {
while((int)c[it].size() > m) c[it].pop_back();
ll x = r[it];
for (int i = 0; i < m; i++) {
e[i] = 1;
while(x % p[i] == 0) {
e[i] *= p[i];
x /= p[i];
}
}
d[0] = 1;
for (int mask = 1; mask < (1 << m); mask++) {
int pos = 0;
while(((mask >> pos) & 1) == 0) pos++;
d[mask] = d[mask ^ (1 << pos)] * e[pos];
if (d[mask] <= k) {
for (int i = 0; i < (int)c[it].size(); i++) {
addTrans(mask, c[it][i]);
}
}
}
}
for (int mask = 0; mask < (1 << m); mask++)
for (int i = 0; i < m; i++)
if (trans[mask][i].second != -1) {
// cerr << mask << " " << trans[mask][i].first << endl;
trans2[trans[mask][i].second].push_back(mask);
}
for (int i = 0; i < n; i++) {
if (trans2[i].empty()) continue;
for (int s = m; s > 0; s--)
for (int nmask : trans2[i]) {
int all = (1 << m) - 1 - nmask;
for (int mask = all;; mask = (mask - 1) & all) {
dp[s][mask ^ nmask] = min(dp[s][mask ^ nmask], dp[s - 1][mask] + a[i].second);
if (mask == 0) break;
}
}
}
ll ans = INF;
for (int i = 0; i <= m; i++)
if (dp[i][(1 << m) - 1] < INF)
ans = min(ans, i * dp[i][(1 << m) - 1]);
if (ans == INF)
printf("-1\n");
else
printf("%lld\n", ans);
return 0;
}