#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int n, m;
int a[N];
set<int> b;
int g[N];
int get_value(int x) {
  int i;
  int res = 0;
  i = 2;
  while (i * i <= x) {
    while (x % i == 0) {
      x /= i;
      if (b.find(i) != b.end())
        res--;
      else
        res++;
    }
    i++;
  }
  if (x != 1)
    if (b.find(x) != b.end())
      res--;
    else
      res++;
  return res;
}
int gcd(int x, int y) {
  int q, temp;
  int r, oldr;
  oldr = x;
  r = y;
  while (r != 0) {
    q = oldr / r;
    temp = r;
    r = oldr - q * r;
    oldr = temp;
  }
  return oldr;
}
int ans;
int main() {
  int i, x;
  int div = 1;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &x);
    b.insert(x);
  }
  for (i = 1; i <= n; i++) {
    ans += get_value(a[i]);
  }
  g[1] = a[1];
  for (i = 2; i <= n; i++) {
    g[i] = gcd(a[i], g[i - 1]);
  }
  for (i = n; i >= 1; i--) {
    x = g[i] / div;
    if (get_value(x) < 0) {
      ans -= i * (get_value(x));
      div *= x;
    }
  }
  printf("%d\n", ans);
  return 0;
}
