#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int maxn = 5005;
int a[maxn];
set<int> b;
int f(int x) {
  int sum = 0;
  int g = sqrt(x) + 2;
  for (int j = 2; j < g; j++) {
    int cnt = 0;
    while (x % j == 0) {
      cnt++;
      x /= j;
    }
    if (cnt) {
      if (b.count(j)) {
        sum -= cnt;
      } else {
        sum += cnt;
      }
    }
  }
  if (x > 1) {
    if (b.count(x)) {
      sum--;
    } else {
      sum++;
    }
  }
  return sum;
}
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
int gg[maxn];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    b.insert(x);
  }
  gg[0] = a[0];
  for (int i = 1; i < n; i++) {
    gg[i] = gcd(gg[i - 1], a[i]);
  }
  int curr = 1;
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (gg[i] == 1) continue;
    int res = f(gg[i] / curr);
    if (res < 0) {
      ans += (i + 1) * (-res);
      curr *= gg[i] / curr;
    }
  }
  for (int i = 0; i < n; i++) ans += f(a[i]);
  cout << ans << endl;
  return 0;
}
