#include <bits/stdc++.h>
using namespace std;
bool search(vector<int>& v, int key, int l, int r) {
  if (l > r) {
    return false;
  }
  int mid = (l + r) / 2;
  if (v[mid] == key) {
    return true;
  } else if (v[mid] < key) {
    return search(v, key, mid + 1, r);
  } else {
    return search(v, key, l, mid - 1);
  }
}
int score(int num, vector<int>& b) {
  int numcpy = num;
  int m = b.size();
  int score = 0;
  for (int j = 2; numcpy > 1 && j * j <= num; j++) {
    int effect = 0;
    while (numcpy % j == 0) {
      numcpy /= j;
      if (effect == 0) {
        effect = 1 - 2 * search(b, j, 0, m - 1);
      }
      score += effect;
    }
  }
  if (numcpy > 1) {
    int effect = 1 - 2 * search(b, numcpy, 0, m - 1);
    score += effect;
  }
  return score;
}
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += score(a[i], b);
  }
  vector<int> gcds(n);
  gcds[0] = a[0];
  for (int i = 1; i < n; i++) {
    gcds[i] = gcd(gcds[i - 1], a[i]);
  }
  int curr_gcd = 1;
  for (int i = n - 1; i >= 0; i--) {
    gcds[i] /= curr_gcd;
    int sc = score(gcds[i], b);
    if (sc < 0) {
      curr_gcd *= gcds[i];
      ans -= sc * (i + 1);
    }
  }
  cout << ans;
  return 0;
}
