#include <bits/stdc++.h>
using namespace std;
int a[100000 + 20], b[100000 + 20], c[100000 + 20];
int tmp[100000 + 20];
map<int, int> hs;
long long ans;
int n, m;
int num;
int prime[100000 + 20];
bool isprime[100000 + 20];
void makeprime() {
  num = 0;
  for (int i = 2; i <= 100000; i++) isprime[i] = true;
  for (int i = 2; i <= 100000; i++) {
    if (isprime[i]) {
      prime[++num] = i;
      for (int j = i + i; j <= 100000; j += i) isprime[j] = false;
    }
  }
}
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int f(int x) {
  if (x == 1) return 0;
  for (int i = 1; i <= num; i++) {
    if (x % prime[i] == 0) {
      return hs[prime[i]] ? f(x / prime[i]) - 1 : f(x / prime[i]) + 1;
    }
  }
  return hs[x] ? -1 : 1;
}
int main() {
  makeprime();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    hs[b[i]] = i;
  }
  bool doit = true;
  while (doit) {
    doit = false;
    tmp[1] = a[1];
    for (int i = 2; i <= n; i++) tmp[i] = gcd(tmp[i - 1], a[i]);
    for (int i = n; i >= 1; i--) {
      if (f(tmp[i]) < 0) {
        for (int j = 1; j <= i; j++) a[j] /= tmp[i];
        doit = true;
        break;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += f(a[i]);
  printf("%I64d\n", ans);
  return 0;
}
