#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
const int MAXN = 6000;
const int MAXP = 40000;
const int MAXNP = 5000;
int n, m, num_p;
int p[MAXNP];
int a[MAXN], b[MAXN], d[MAXN];
int deg[MAXN][MAXNP];
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int func(int a) {
  int ans = 0;
  for (int i = 0; i < m && b[i] <= a; ++i) {
    while (a % b[i] == 0) {
      ans--;
      a /= b[i];
    }
  }
  for (int i = 0; i < num_p && p[i] * p[i] <= a; ++i) {
    while (a % p[i] == 0) {
      ans++;
      a /= p[i];
    }
  }
  if (a > 1) ans++;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  num_p = 0;
  for (int i = 2; i < MAXP; ++i) {
    bool key = true;
    for (int j = 0; j < num_p && p[j] * p[j] <= i; ++j) {
      if (i % p[j] == 0) {
        key = false;
        break;
      }
    }
    if (key) {
      p[num_p++] = i;
    }
  }
  n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int j = 0; j < m; ++j) {
    cin >> b[j];
  }
  d[0] = a[0];
  for (int i = 1; i < n; ++i) {
    d[i] = gcd(d[i - 1], a[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += func(a[i]);
  }
  int d_cur = 1;
  for (int i = n - 1; i >= 0; --i) {
    int f1 = func(d[i] / d_cur);
    if (f1 < 0) {
      ans -= f1 * (i + 1);
      d_cur = d[i];
    }
  }
  cout << ans << endl;
  return 0;
}
