#include <bits/stdc++.h>
using namespace std;
struct data {
  int x, y;
  long long val;
};
long long read() {
  long long tmp = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    tmp = tmp * 10 + c - '0';
    c = getchar();
  }
  return tmp;
}
data change[2000000];
long long val[1000010], num[13000], prime[100], mx, mi[13000][100], ch[100],
    f[20][2100];
bool able[13000][2100];
int cnt_change;
int cost[1000010], tot_prime, cnt, type[1000010], peo[1000010], full,
    sum_type[13000], sum_trans[2100];
map<long long, int> id;
bool cmp(int a, int b) { return cost[a] < cost[b]; }
long long get_gcd(long long a, long long b) {
  if (a == 0) return b;
  long long y = a % b;
  while (y) {
    a = b;
    b = y;
    y = a % b;
  }
  return b;
}
void dfs(int dep, long long cur) {
  if (dep > tot_prime) {
    num[++cnt] = cur;
    id[cur] = cnt;
    for (int i = 1; i <= dep; i++) mi[cnt][i] = ch[i];
    return;
  }
  ch[dep] = 1;
  while (mx / cur >= prime[dep]) {
    ch[dep] *= prime[dep];
    cur *= prime[dep];
    dfs(dep + 1, cur);
  }
}
void get_trans(int x, int cost) {
  for (int i = 1; i <= tot_prime; i++) {
    if (f[i - 1][0] != -1 && (f[i - 1][0] + cost < f[i][x] || f[i][x] == -1))
      change[++cnt_change] = (data){i, x, f[i - 1][0] + cost};
    for (int s = full - x; s; s = (s - 1) & (full - x)) {
      if (f[i - 1][s] != -1 &&
          (f[i - 1][s] + cost < f[i][s + x] || f[i][s + x] == -1))
        change[++cnt_change] = (data){i, s + x, f[i - 1][s] + cost};
    }
  }
}
int main() {
  int n = read();
  long long K = read(), g = 0;
  for (int i = 1; i <= n; i++) {
    val[i] = read();
    g = get_gcd(g, val[i]);
    mx = max(mx, val[i]);
    peo[i] = i;
  }
  if (g == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++) cost[i] = read();
  for (int i = 2; (long long)i * i <= g; i++)
    if (g % i == 0) {
      prime[++tot_prime] = i;
      while (g % i == 0) g /= i;
    }
  if (g != 1) prime[++tot_prime] = g;
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    long long now = 1;
    for (int j = 1; j <= tot_prime; j++)
      while (val[i] % prime[j] == 0) {
        val[i] /= prime[j];
        now *= prime[j];
      }
    type[i] = id[now];
  }
  full = (1 << tot_prime) - 1;
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= full; j++) {
      long long need = 1;
      for (int k = 1; k <= tot_prime; k++)
        if ((j >> k - 1) & 1) need *= mi[i][k];
      if (need <= K) able[i][j] = 1;
    }
  sort(peo + 1, peo + n + 1, cmp);
  for (int i = 0; i <= tot_prime; i++)
    for (int j = 0; j <= full; j++) f[i][j] = -1;
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int tmp = peo[i];
    if (sum_type[type[tmp]] < tot_prime) {
      sum_type[type[tmp]]++;
      cnt_change = 0;
      for (int j = 0; j <= full; j++)
        if (sum_trans[j] < tot_prime && able[type[tmp]][j]) {
          sum_trans[j]++;
          get_trans(j, cost[tmp]);
        }
      for (int j = 1; j <= cnt_change; j++)
        f[change[j].x][change[j].y] = change[j].val;
    }
  }
  long long res = -1;
  for (int i = 1; i <= tot_prime; i++)
    if (f[i][full] != -1 && (i * f[i][full] < res || res == -1))
      res = i * f[i][full];
  printf("%lld\n", res);
  return 0;
}
