#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (a) {
    int t = b % a;
    b = a;
    a = t;
  }
  return b;
}
set<int> bad;
int count(int x) {
  int res = 0;
  for (int i = 2; i * i <= x; i++)
    while (x % i == 0) {
      res += -2 * bad.count(i) + 1;
      x /= i;
    }
  if (x != 1) res += -2 * bad.count(x) + 1;
  return res;
}
int g[5100];
int a[5100];
int dp[5100];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < m; j++) {
    int b;
    cin >> b;
    bad.insert(b);
  }
  int res = a[0];
  g[0] = count(res);
  for (int i = 1; i < n; i++) {
    res = gcd(res, a[i]);
    g[i] = count(res);
  }
  for (int i = 0; i < n; i++) {
    int here = max(0, -g[i]);
    dp[i] = here * (i + 1);
    for (int j = 0; j < i; j++) dp[i] = max(dp[i], here * (i - j) + dp[j]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, dp[i]);
  for (int i = 0; i < n; i++) ans += count(a[i]);
  printf("%d\n", ans);
}
