#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, maxn = 5e5 + 5, srt = 32005;
int n, m;
int a[maxn], b[maxn], gd[maxn], bd[maxn];
set<int> vc;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int notpm[maxn], pm[maxn], pcnt = 0;
void xxs() {
  notpm[1] = 1;
  for (int i = 2; i <= srt - 5; i++) {
    if (!notpm[i]) pm[++pcnt] = i;
    for (int j = 1; j <= pcnt && pm[j] * i <= srt - 5; j++) {
      notpm[i * pm[j]] = 1;
      if (i % pm[j] == 0) break;
    }
  }
}
int f(int curx) {
  int r = 0;
  for (int j = 1; j <= pcnt; j++) {
    if (curx == 1) break;
    while (curx % pm[j] == 0) {
      curx /= pm[j];
      if (vc.find(pm[j]) == vc.end())
        ++r;
      else
        --r;
    }
  }
  if (curx != 1) {
    if (vc.find(curx) == vc.end())
      ++r;
    else
      --r;
  }
  return r;
}
signed main() {
  xxs();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    vc.insert(b[i]);
  }
  gd[1] = a[1];
  for (int i = 2; i <= n; i++) {
    gd[i] = gd[i - 1];
    if (gd[i] == 1) continue;
    gd[i] = gcd(gd[i], a[i]);
  }
  int bs = 1;
  for (int i = n; i >= 1; i--) {
    int tmp = f(gd[i] / bs);
    if (tmp < 0) bs = gd[i];
    a[i] /= bs;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += f(a[i]);
  printf("%d\n", ans);
  return 0;
}
