#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
long long p[1100];
long long dp[1 << 12][13];
long long dp1[1 << 12][13];
long long ff[1 << 12];
int used[1 << 12];
int len;
long long a[1100000];
long long b[1100000];
long long mul[1100000];
int id[1100000];
int e[1100000];
unordered_map<long long, int> app;
bool cmp(int x, int y) { return e[x] < e[y]; }
long long gcd(long long x, long long y) {
  if (!x) return y;
  return gcd(y % x, x);
}
void conv(int mask, int e) {
  for (int i = len - 1; i >= 0; i--)
    for (int j = 0; j < (1 << len); j++)
      if (__builtin_popcount(j & mask) == 0)
        dp[j | mask][i + 1] = min(dp[j | mask][i + 1], dp1[j][i] + e);
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &e[i]);
  long long GCD = 0;
  for (int i = 1; i <= n; i++) GCD = gcd(GCD, a[i]);
  for (long long ll = 2; ll * ll <= GCD; ll++)
    if (GCD % ll == 0) {
      p[len] = ll;
      len++;
      while (GCD % ll == 0) GCD /= ll;
    }
  if (GCD > 1) p[len++] = GCD;
  if (len == 0) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    b[i] = 1;
    for (int j = 0; j < len; j++)
      while (a[i] % p[j] == 0) {
        b[i] *= p[j];
        a[i] /= p[j];
      }
  }
  for (int i = 1; i <= n; i++) id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  for (int i = 0; i < (1 << len); i++)
    for (int j = 0; j <= len; j++) dp[i][j] = 1e16;
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    app[b[id[i]]]++;
    if (app[b[id[i]]] > len) continue;
    for (int j = 0; j < len; j++) {
      mul[j] = 1;
      while (b[id[i]] % p[j] == 0) {
        mul[j] *= p[j];
        b[id[i]] /= p[j];
      }
    }
    bool FIRST = false;
    ff[0] = 1;
    for (int j = 1; j < 1 << len; ++j) {
      int p = __builtin_ctz(j);
      ff[j] = ff[j ^ 1 << p] * mul[p];
      if (ff[j] <= k && used[j] < len) {
        if (!FIRST) {
          memcpy(dp1, dp, sizeof dp);
          FIRST = true;
        }
        conv(j, e[id[i]]);
        used[j]++;
      }
    }
  }
  long long ans = 1e18;
  for (int i = 1; i <= len; i++)
    ans = min(ans, 1LL * i * dp[(1 << len) - 1][i]);
  if (ans < 1e15)
    printf("%lld\n", ans);
  else
    printf("-1\n");
}
