#include <bits/stdc++.h>
using namespace std;
const int max_n = 5000 + 20;
int a[max_n], gcd[max_n];
set<int> b;
int GCD(int n, int m);
int check(int n);
int main() {
  ios_base ::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  while (m--) {
    int x;
    cin >> x;
    b.insert(x);
  }
  gcd[0] = a[0];
  int ans = check(a[0]);
  for (int i = 1; i < n; i++) {
    gcd[i] = GCD(gcd[i - 1], a[i]);
    ans += check(a[i]);
  }
  int p = 1;
  for (int i = n - 1; i >= 0; i--) {
    int x = check(gcd[i] / p);
    if (x < 0) {
      ans -= (i + 1) * x;
      p = gcd[i];
    }
  }
  cout << ans;
  return 0;
}
int check(int n) {
  int ans = 0;
  while (n % 2 == 0) {
    n /= 2;
    ans++;
  }
  if (b.count(2)) {
    ans *= -1;
  }
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      int x = 0;
      while (n % i == 0) {
        n /= i;
        x++;
      }
      if (b.count(i))
        ans -= x;
      else
        ans += x;
    }
  }
  if (n > 1) {
    if (b.count(n))
      ans--;
    else
      ans++;
  }
  return ans;
}
int GCD(int n, int m) {
  if (m == 0)
    return n;
  else
    return GCD(m, n % m);
}
