#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[5005], b[5005], g[5005];
int GCD(int x, int y) {
  if (x > y) swap(x, y);
  return x == 0 ? y : GCD(y % x, x);
}
int Proc(int x) {
  int ret = 0;
  for (int i = 0; i < m; ++i) {
    while (x % b[i] == 0) {
      x /= b[i];
      --ret;
    }
  }
  for (int i = 2; i * i <= x; ++i) {
    while (x % i == 0) {
      x /= i;
      ++ret;
    }
  }
  if (x != 1) ++ret;
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  g[0] = a[0];
  for (int i = 1; i < n; ++i) {
    g[i] = GCD(g[i - 1], a[i]);
  }
  for (int i = 0; i < m; ++i) scanf("%d", &b[i]);
  int ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    int t = Proc(g[i]);
    if (t < 0) {
      for (int j = i, gt = g[i]; j >= 0; --j) g[j] /= gt, a[j] /= gt;
    }
    ans += Proc(a[i]);
  }
  printf("%d\n", ans);
  return 0;
}
