#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }

//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };

#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

#define REP(i,b) for(int i=0;i<(b);i++)
#define REPP(i,b) for(int i=1;i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>(b);i++)
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(s) memset(s, 0, sizeof(s))
#define PB push_back
#define MP make_pair

typedef vector<pair<int, int>> VPII;
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = (int) 1e9 + 7;
string ascii_lowercase = "abcdefghijklmnopqrstuvwxyz";
string ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

struct hashLL { /* mp.rehash(n << 2); */
    size_t operator()(ll x) const {
        x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
        x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb);
        x = x ^ (x >> 31);
        return x;
    }
};

long long inv(long long a, long long b) {
    return 1 < a ? b - inv(b % a, a) * b / a : 1;
}

const ll INF = 1e6;

// unordered_map<int, int, custom_hash> mp;
// unordered_map<int, unordered_map<int, int, custom_hash>, custom_hash> g;

ll gcd(ll a, ll b, ll &x, ll &y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

ll distsq(ll x1, ll y1, ll x2, ll y2) {
    return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
}

const int N = 5001;
ll n, m, k;
ll arr[N];
unordered_set<ll> bb;
vector<ll> primes;
const int maxp = 34000;
bool aprimes[maxp];
int main() {
    // freopen("input.txt", "r", stdin); freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    REP(i,n) { cin >> arr[i]; }
    REP(i,m) { cin >> k; bb.insert(k); }
    REP(i, maxp) {
        aprimes[i]=true;
    }
    for (int i = 2; i < maxp; i++) {
        if (aprimes[i]) {
            primes.PB(i);
            for (int j = i * i; j < maxp; j+=i) {
                aprimes[j]=false;
            }
        }
    }
    // dbg(primes);
    ll tot = 0;
    ll d = arr[0];
    vector<ll> diffs;
    REP(i,n) {
        d = __gcd(d, arr[i]);
        ll currd = d;
        ll currdiff = 0;
        ll curr = arr[i];
        for (auto p : primes) {
            bool isbad = bb.count(p);
            while (curr%p==0) {
                curr/=p;
                if (isbad) tot--;
                else tot++;
            }
            while(currd%p==0) {
                currd/=p;
                if (isbad)currdiff++;
                else currdiff--;
            }
        }
        if (curr != 1) {
            if (bb.count(curr)) tot--;
            else tot++;
        }
        if (currd != 1) {
            if (bb.count(currd)) currdiff++;
            else currdiff--;
        }
        // dbgm(i, d, currdiff);
        diffs.PB(currdiff);
    }
    // dbg(diffs);
    ll currtotdiff = 0;
    for (int i = n - 1; i >= 0; i--) {
        ll currdiff = diffs[i];
        if (n==193 && m == 1) {
            dbgm(i, tot, currdiff, currtotdiff, *bb.begin());
        }
        if (currdiff - currtotdiff > 0) {
            tot += (currdiff-currtotdiff) * (i + 1);
            currtotdiff += currdiff;
        }
    }
    cout << tot;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=32000;

map<int,int> f;
set<int> bad;
vector<ll> ps;

inline ll eval2(int x) {
	return bad.count(x) ? -1 : 1;
}

ll eval(ll x) {
	ll y=x;
	if(f.count(x))
		return f[x];
	ll ret=0;
	for (auto p : ps) {
		if(x<p*p) break;
		while(x%p==0) x/=p, ret+=eval2(p);
	}
	if(x>1) ret+=eval2(x);
	return f[y]=ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	vector<int> a(n+1);
	for (int i=1; i<=n; i++)
		cin>>a[i];
	for (int i=1; i<=m; i++) {
		int x; cin>>x; bad.insert(x);
	}
	vector<int> div;
	for (int d=1; d*d<=a[1]; d++)
		if(a[1]%d==0)
			div.push_back(d), div.push_back(a[1]/d);
	vector<bool> flag(mx,true);
	flag[0]=flag[1]=false;
	for (int i=2; i*i<mx; i++)
		if(flag[i])
			for (int j=i; j*i<mx; j++)
				flag[i*j]=false;
	for (int i=0; i<mx; i++)
		if(flag[i])
			ps.push_back(i);
	for (auto x : div)
		f[x]=eval(x);

	ll ret=0;
	for (int i=1; i<=n; i++)
		ret+=eval(a[i]);
	vector<int> g(n+1);
	g[1]=a[1];
	for (int i=2; i<=n; i++)
		g[i]=__gcd(g[i-1],a[i]);
	ll used=1;
	for (int r=n; r>=1; r--) {
		ll cur=g[r];
		if(f[cur/used]<0)
			ret-=r*f[cur/used], used=cur;
	}
	cout<<ret<<"\n";
	return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=32000;

map<int,int> f;
set<int> bad;
vector<ll> ps;

inline ll eval2(int x) {
	return bad.count(x) ? -1 : 1;
}

ll eval(ll x) {
	ll y=x;
	if(f.count(x))
		return f[x];
	ll ret=0;
	for (auto p : ps) {
		if(x<p*p) break;
		while(x%p==0) x/=p, ret+=eval2(p);
	}
	if(x>1) ret+=eval2(x);
	return f[y]=ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	vector<int> a(n+1);
	for (int i=1; i<=n; i++)
		cin>>a[i];
	for (int i=1; i<=m; i++) {
		int x; cin>>x; bad.insert(x);
	}
	vector<int> div;
	for (int d=1; d*d<=a[1]; d++)
		if(a[1]%d==0)
			div.push_back(d), div.push_back(a[1]/d);
	vector<bool> flag(mx,true);
	flag[0]=flag[1]=false;
	for (int i=2; i*i<mx; i++)
		if(flag[i])
			for (int j=i; j*i<mx; j++)
				flag[i*j]=false;
	for (int i=0; i<mx; i++)
		if(flag[i])
			ps.push_back(i);
	for (auto x : div)
		f[x]=eval(x);

	ll ret=0;
	for (int i=1; i<=n; i++)
		ret+=eval(a[i]);
	vector<int> g(n+1);
	g[1]=a[1];
	for (int i=2; i<=n; i++)
		g[i]=__gcd(g[i-1],a[i]);
	ll used=1;
	for (int r=n; r>=1; r--) {
		ll cur=g[r];
		if(f[cur/used]<0)
			ret-=r*f[cur/used], used=cur;
	}
	cout<<ret<<"\n";
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=32000;

map<int,int> f;
set<int> bad;
vector<ll> ps;

inline ll eval2(int x) {
	return bad.count(x) ? -1 : 1;
}

ll eval(ll x) {
	ll y=x;
	if(f.count(x))
		return f[x];
	ll ret=0;
	for (auto p : ps) {
		if(x<p*p) break;
		while(x%p==0) x/=p, ret+=eval2(p);
	}
	if(x>1) ret+=eval2(x);
	return f[y]=ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	vector<int> a(n+1);
	for (int i=1; i<=n; i++)
		cin>>a[i];
	for (int i=1; i<=m; i++) {
		int x; cin>>x; bad.insert(x);
	}
	vector<int> div;
	for (int d=1; d*d<=a[1]; d++)
		if(a[1]%d==0)
			div.push_back(d), div.push_back(a[1]/d);
	vector<bool> flag(mx,true);
	flag[0]=flag[1]=false;
	for (int i=2; i*i<mx; i++)
		if(flag[i])
			for (int j=i; j*i<mx; j++)
				flag[i*j]=false;
	for (int i=0; i<mx; i++)
		if(flag[i])
			ps.push_back(i);
	for (auto x : div)
		eval(x);

	ll ret=0;
	for (int i=1; i<=n; i++)
		ret+=eval(a[i]);
	vector<int> g(n+1);
	g[1]=a[1];
	for (int i=2; i<=n; i++)
		g[i]=__gcd(g[i-1],a[i]);
	ll used=1;
	for (int r=n; r>=1; r--) {
		ll cur=g[r];
		if(f[cur/used]<0)
			ret-=r*f[cur/used], used=cur;
	}
	cout<<ret<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N = 1E4 + 1;
ll n,m,arr[N],brr[N];
ll ptsfun(ll val)
{
  ll pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(ll i = 2;i<=sqrt(val);i++)
  {
    if(no%i==0)
    {
      ll f = 0;
      while(pre<m&&brr[pre]<i) pre++;
      if(pre<m&&brr[pre]==i) f = -1;
      else f = 1;
      while(no%i==0)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    while(pre<m&&brr[pre]<no) pre++;
    if(pre<m&&brr[pre]==no) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  cin>>n>>m;
  for(ll i = 0;i<n;i++) cin>>arr[i];
  for(ll i = 0;i<m;i++) cin>>brr[i];
  ll pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  ll pre = arr[0];
  for(ll i = 0;i<n;i++)
  {
    pre = __gcd(pre,arr[i]);
    ll pt = ptsfun(pre);
    //     cout<<pre<<" "<<pt<<" "<<i<<endl;
    if(pt<=0) pts-=pt;
  }
  ll pt = ptsfun(pre);
  if(pt<=0) pts-=pt*(n-1-0+1);
  cout<<pts<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
const int N = 1E4 + 1;
ll n,m,arr[N],brr[N];
long long int ptsfun(ll val)
{
  long long int pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(ll i = 2;i<=sqrt(no);i++)
  {
    if(i>no) break;
    if(no%i==0)
    {
      ll f = 0;
      while(pre<m&&brr[pre]<i) pre++;
      if(pre<m&&brr[pre]==i) f = -1;
      else f = 1;
      while(no%i==0&&no>1)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    while(pre<m&&brr[pre]<no) pre++;
    if(pre<m&&brr[pre]==no) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  scanf("%d %d",&n,&m);
  ll pre[n];
  for(ll i = 0;i<n;i++)
  {
    scanf("%d",&arr[i]);
    pre[i] = arr[i];
    if(i!=0) pre[i] = __gcd(pre[i-1],pre[i]);
  }
  for(ll i = 0;i<m;i++) scanf("%d",&brr[i]);
  long long int pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  //   cout<<pts<<" ";
  for(ll i = n-1;i>=0;i--)
  {
    long long int pt = ptsfun(pre[i]);
    if(pt<=0)
    { pts-=pt*(i-0+1);
      ll pr = pre[i];
      for(ll j = i;j>=0;j--) pre[j]/=pr;
    }
  }
  printf("%lld",pts);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N = 1E4 + 1;
ll n,m,arr[N],brr[N];
ll ptsfun(ll val)
{
  ll pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(ll i = 2;i<=sqrt(val);i++)
  {
    if(i>no) break;
    if(no%i==0)
    {
      ll f = 0;
      while(pre<m&&brr[pre]<i) pre++;
      if(pre<m&&brr[pre]==i) f = -1;
      else f = 1;
      while(no%i==0&&no>1)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    while(pre<m&&brr[pre]<no) pre++;
    if(pre<m&&brr[pre]==no) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  cin>>n>>m;
  ll pre[n];
  for(ll i = 0;i<n;i++)
  {
    cin>>arr[i];
    pre[i] = arr[i];
    if(i!=0) pre[i] = __gcd(pre[i-1],pre[i]);
  }
  for(ll i = 0;i<m;i++) cin>>brr[i];
  ll pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  //   cout<<pts<<" ";
  for(ll i = n-1;i>=0;i--)
  {
    ll pt = ptsfun(pre[i]);
    if(pt<=0)
    { pts-=pt*(i-0+1);
      ll pr = pre[i];
      for(ll j = i;j>=0;j--) pre[j]/=pr;
    }
  }
  cout<<pts<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
const int N = 1E4 + 1;
ll n,m,arr[N],brr[N];
long long int ptsfun(ll val)
{
  ll prm[N];
  fill(prm,prm+N,1);
  prm[0] = prm[1] = 0;
  vector<ll> primes;
  for(ll i = 2;i<N;i++)
  {
    if(prm[i])
    {
      for(ll j = 2*i;j<N;j+=i)
      {
        prm[j] = 0;
      }
    }
  }
  for(ll i = 2;i<N;i++) if(prm[i]) primes.push_back(i);
  long long int pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(auto i : primes)
  {
    if(i>no) break;
    if(no%i==0)
    {
      ll f = 0;
      while(pre<m&&brr[pre]<i) pre++;
      if(pre<m&&brr[pre]==i) f = -1;
      else f = 1;
      while(no%i==0&&no>1)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    while(pre<m&&brr[pre]<no) pre++;
    if(pre<m&&brr[pre]==no) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  scanf("%d %d",&n,&m);
  ll pre[n];
  for(ll i = 0;i<n;i++)
  {
    scanf("%d",&arr[i]);
    pre[i] = arr[i];
    if(i!=0) pre[i] = __gcd(pre[i-1],pre[i]);
  }
  for(ll i = 0;i<m;i++) scanf("%d",&brr[i]);
  long long int pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  //   cout<<pts<<" ";
  for(ll i = n-1;i>=0;i--)
  {
    long long int pt = ptsfun(pre[i]);
    if(pt<=0)
    { pts-=pt*(i-0+1);
      ll pr = pre[i];
      for(ll j = i;j>=0;j--) pre[j]/=pr;
    }
  }
  printf("%lld",pts);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N = 1E4 + 1;
ll n,m,arr[N];
set<ll> brr;
ll ptsfun(ll val)
{
  ll pts = 0;
  if(val<=1) return pts;
  ll no = val;
  for(ll i = 2;i<=sqrt(val);i++)
  {
    if(no%i==0)
    {
      ll f = 0;
      if(brr.count(i)==0) f = 1;
      else f  = -1;
      while(no%i==0)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    if(brr.count(no)==0) f = 1;
    else f = -1;
    pts+=f;
  }
  return pts;
}
int main()
{
  cin>>n>>m;
  ll pre[n];
  for(ll i = 0;i<n;i++)
  {
    cin>>arr[i];
    pre[i] = arr[i];
    if(i!=0) pre[i] = __gcd(pre[i-1],pre[i]);
  }
  for(ll i = 0;i<m;i++)
  {
    ll x; cin>>x;
    brr.insert(x);
  }
  ll pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  //   cout<<pts<<" ";
  for(ll i = n-1;i>=0;i--)
  {
    ll pt = ptsfun(pre[i]);
    if(pt<=0)
    { pts-=pt*(i-0+1);
  ll pr = pre[i];
      for(ll j = i;j>=0;j--) pre[j]/=pr;
    }
  }
  cout<<pts<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N = 1E4 + 1;
ll n,m,arr[N],brr[N];
ll ptsfun(ll val)
{
  ll pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(ll i = 2;i<=sqrt(val);i++)
  {
    if(no%i==0)
    {
      ll f = 0;
      while(pre<m&&brr[pre]<i) pre++;
      if(pre<m&&brr[pre]==i) f = -1;
      else f = 1;
      while(no%i==0)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    while(pre<m&&brr[pre]<no) pre++;
    if(pre<m&&brr[pre]==no) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  cin>>n>>m;
  for(ll i = 0;i<n;i++) cin>>arr[i];
  for(ll i = 0;i<m;i++) cin>>brr[i];
  ll pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  ll pre = arr[0];
  for(ll i = 0;i<n;i++)
  {
    pre = __gcd(pre,arr[i]);
    ll pt = ptsfun(pre);
//          cout<<pre<<" "<<pt<<" "<<i<<endl;
    if(pt<=0) pts-=pt;
  }
  cout<<pts<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
const int N = 1E5 + 1;
ll n,m,arr[N];
set<ll> brr;
vector<ll> primes;
void primefun()
{
  ll prm[N];
  fill(prm,prm+N,1);
  prm[0] = prm[1] = 0;
  for(ll i = 2;i<N;i++)
  {
    if(prm[i])
    {
      for(ll j = 2*i;j<N;j+=i)
      {
        prm[j] = 0;
      }
    }
  }
  for(ll i = 2;i<N;i++) if(prm[i]) primes.push_back(i);
}
long long int ptsfun(ll val)
{
  long long int pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(auto i : primes)
  {
    if(i>sqrt(no)) break;
    if(no%i==0)
    {
      ll f = 0;
      if(brr.count(i)!=0) f = -1;
      else f = 1;
      while(no%i==0&&no>1)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    if(brr.count(no)!=0) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  primefun();
  scanf("%d %d",&n,&m);
  ll pre[n];
  for(ll i = 0;i<n;i++)
  {
    scanf("%d",&arr[i]);
    pre[i] = arr[i];
    if(i!=0) pre[i] = __gcd(pre[i-1],pre[i]);
  }
  for(ll i = 0;i<m;i++)
  {
    ll x;
    scanf("%d",&x);
    brr.insert(x);
  }
  long long int pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  //   cout<<pts<<" ";
  for(ll i = n-1;i>=0;i--)
  {
    long long int pt = ptsfun(pre[i]);
    if(pt<=0)
    { pts-=pt*(i-0+1);
      ll pr = pre[i];
      for(ll j = i;j>=0;j--) pre[j]/=pr;
    }
  }
  printf("%lld",pts);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
const int N = 1E5 + 1;
ll n,m,arr[N],brr[N];
long long int ptsfun(ll val)
{
  ll prm[N];
  fill(prm,prm+N,1);
  prm[0] = prm[1] = 0;
  vector<ll> primes;
  for(ll i = 2;i<N;i++)
  {
    if(prm[i])
    {
      for(ll j = 2*i;j<N;j+=i)
      {
        prm[j] = 0;
      }
    }
  }
  for(ll i = 2;i<N;i++) if(prm[i]) primes.push_back(i);
  long long int pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(auto i : primes)
  {
    if(i>no) break;
    if(no%i==0)
    {
      ll f = 0;
      while(pre<m&&brr[pre]<i) pre++;
      if(pre<m&&brr[pre]==i) f = -1;
      else f = 1;
      while(no%i==0&&no>1)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    while(pre<m&&brr[pre]<no) pre++;
    if(pre<m&&brr[pre]==no) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  scanf("%d %d",&n,&m);
  ll pre[n];
  for(ll i = 0;i<n;i++)
  {
    scanf("%d",&arr[i]);
    pre[i] = arr[i];
    if(i!=0) pre[i] = __gcd(pre[i-1],pre[i]);
  }
  for(ll i = 0;i<m;i++) scanf("%d",&brr[i]);
  long long int pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  //   cout<<pts<<" ";
  for(ll i = n-1;i>=0;i--)
  {
    long long int pt = ptsfun(pre[i]);
    if(pt<=0)
    { pts-=pt*(i-0+1);
      ll pr = pre[i];
      for(ll j = i;j>=0;j--) pre[j]/=pr;
    }
  }
  printf("%lld",pts);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N = 1E4 + 1;
ll n,m,arr[N],brr[N];
ll ptsfun(ll val)
{
  ll pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(ll i = 2;i<=sqrt(val);i++)
  {
    if(no%i==0)
    {
      ll f = 0;
      while(pre<m&&brr[pre]<i) pre++;
      if(pre<m&&brr[pre]==i) f = -1;
      else f = 1;
      while(no%i==0)
        no/=i, pts+=f;
  }
  }
  if(no>1)
  {
    ll f = 0;
    while(pre<m&&brr[pre]<no) pre++;
    if(pre<m&&brr[pre]==no) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  cin>>n>>m;
  for(ll i = 0;i<n;i++) cin>>arr[i];
  for(ll i = 0;i<m;i++) cin>>brr[i];
  ll pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  ll pre = arr[0];
  for(ll i = 1;i<n;i++)
  {
    ll g = __gcd(pre,arr[i]);
    if(g==pre) continue;
    else
    {
      pre/=g;
      ll pt = ptsfun(pre);
      if(pt<=0)
      {
        pts-=pt*(i-1-0+1);
      }
      pre = g;
    }
  }
  ll pt = ptsfun(pre);
  if(pt<=0) pts-=pt*(n-1-0+1);
  cout<<pts<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
const int N = 1E5 + 1;
ll n,m,arr[N];
set<ll> brr;
long long int ptsfun(ll val)
{
  ll prm[N];
  fill(prm,prm+N,1);
  prm[0] = prm[1] = 0;
  vector<ll> primes;
  for(ll i = 2;i<N;i++)
  {
    if(prm[i])
    {
      for(ll j = 2*i;j<N;j+=i)
      {
        prm[j] = 0;
      }
    }
  }
  for(ll i = 2;i<N;i++) if(prm[i]) primes.push_back(i);
  long long int pts = 0;
  if(val<=1) return pts;
  ll no = val,pre=0;
  for(auto i : primes)
  {
    if(i>sqrt(no)) break;
    if(no%i==0)
    {
      ll f = 0;
      if(brr.count(i)!=0) f = -1;
      else f = 1;
      while(no%i==0&&no>1)
        no/=i, pts+=f;
    }
  }
  if(no>1)
  {
    ll f = 0;
    if(brr.count(no)!=0) f = -1;
    else f = 1;
    pts+=f;
  }
  return pts;
}
int main()
{
  scanf("%d %d",&n,&m);
  ll pre[n];
  for(ll i = 0;i<n;i++)
  {
    scanf("%d",&arr[i]);
    pre[i] = arr[i];
    if(i!=0) pre[i] = __gcd(pre[i-1],pre[i]);
  }
  for(ll i = 0;i<m;i++)
  {
    ll x;
    scanf("%d",&x);
    brr.insert(x);
  }
  long long int pts = 0;
  for(ll i = 0;i<n;i++) pts+=ptsfun(arr[i]);
  //   cout<<pts<<" ";
  for(ll i = n-1;i>=0;i--)
  {
    long long int pt = ptsfun(pre[i]);
    if(pt<=0)
    { pts-=pt*(i-0+1);
      ll pr = pre[i];
      for(ll j = i;j>=0;j--) pre[j]/=pr;
    }
  }
  printf("%lld",pts);
  return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
	re int num;
	re char c;
	while(!isdigit(c=gc()));num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return num;
}

inline int gcd(int a,int b){
	int tmp;
	while(b){
		tmp=a-a/b*b;
		a=b;
		b=tmp;
	}
	return a;
}

cs int P=1000006;
bool mark[P];
int prime[P],pcnt;
bool isbad[P];
int f[P];
set<int> badprimes;
inline void linear_sieves(int len=P-6){
	for(int re i=2;i<=len;++i){
		if(!mark[i])prime[++pcnt]=i,f[i]=isbad[i]?-1:1;
		for(int re j=1;j<=pcnt&&i*prime[j]<=len;++j){
			mark[i*prime[j]]=true;
			f[i*prime[j]]=f[i]+((isbad[prime[j]])?-1:1);
			if(i%prime[j]==0)break;
		}
	}
}

inline bool isbadprime(int a){
	if(a<=P-6)return isbad[a];
	else return badprimes.find(a)!=badprimes.end();
}

tr1::unordered_map<int,int> FF;
inline int F(int a){
	if(a<=P-6)return f[a];
	else if(FF.find(a)!=FF.end())return FF[a];
	int pos=0;
	for(int re i=1;i<=pcnt&&prime[i]*prime[i]<=a;++i)if(a%prime[i]==0){
		pos=i;break;
	}
	if(pos)return FF[a]=(isbad[prime[pos]]?-1:1)+F(a/prime[pos]);
	else return FF[a]=isbadprime(a)?-1:1;
}

cs int N=5003;
int n,m;
int a[N],g[N];
vector<int> ed[N];
int suf;
int ans;
int maxn[N][N];

signed main(){
	n=getint();
	m=getint();
	for(int re i=1;i<=n;++i){
		a[i]=getint();
		if(i>1)g[i]=gcd(g[i-1],a[i]);
		else g[i]=a[i];
		ed[i].push_back(a[i]);
	}

	for(int re i=1;i<=m;++i){
		int b=getint();
		if(b<=P-6)isbad[b]=true;
		badprimes.insert(b);
	}

	linear_sieves();
	for(int re i=1;i<=n;++i)ans+=F(a[i]);

	for(int re i=n;i;--i){
		int now=g[i];
		suf+=F(a[i]);
		int sum=suf;
		for(int re j=i;j;--j)sum+=F(a[j]/now),ed[j].push_back(a[j]/now);
		ans=max(ans,sum);
	}
	memset(maxn,-0x3f,sizeof maxn);
	for(int re i=ed[1].size()-1;~i;--i){
		maxn[1][i]=max(F(ed[1][i]),maxn[1][i+1]);
	}

	for(int re i=2;i<=n;++i){
		for(int re j=ed[i].size()-1;~j;--j){
			maxn[i][j]=max(maxn[i][j+1],F(ed[i][j])+maxn[i-1][j]);
		}
	}
	for(int re i=ed[n].size()-1;~i;--i){
		ans=max(ans,maxn[n][i]);
	}

	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
	re int num;
	re char c;
	while(!isdigit(c=gc()));num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return num;
}

inline int gcd(int a,int b){
	int tmp;
	while(b){
		tmp=a-a/b*b;
		a=b;
		b=tmp;
	}
	return a;
}

cs int P=1000006;
bool mark[P];
int prime[P],pcnt;
bool isbad[P];
int f[P];
set<int> badprimes;
inline void linear_sieves(int len=P-6){
	for(int re i=2;i<=len;++i){
		if(!mark[i])prime[++pcnt]=i,f[i]=isbad[i]?-1:1;
		for(int re j=1;j<=pcnt&&i*prime[j]<=len;++j){
			mark[i*prime[j]]=true;
			f[i*prime[j]]=f[i]+((isbad[prime[j]])?-1:1);
			if(i%prime[j]==0)break;
		}
	}
}

inline bool isbadprime(int a){
	if(a<=P-6)return isbad[a];
	else return badprimes.find(a)!=badprimes.end();
}

tr1::unordered_map<int,int> FF;
inline int F(int a){
	if(a<=P-6)return f[a];
	else if(FF.find(a)!=FF.end())return FF[a];
	int pos=0;
	for(int re i=1;i<=pcnt&&prime[i]*prime[i]<=a;++i)if(a%prime[i]==0){
		pos=i;break;
	}
	if(pos)return FF[a]=(isbad[prime[pos]]?-1:1)+F(a/prime[pos]);
	else return FF[a]=isbadprime(a)?-1:1;
}

cs int N=5003;
int n,m;
int a[N],g[N],b[N];
vector<int> ed[N];
int suf[N];
int ans;
int sum[N][N];
int maxn[N][N];

signed main(){
	n=getint();
	m=getint();
	for(int re i=1;i<=n;++i){
		a[i]=getint();
		if(i>1)g[i]=gcd(g[i-1],a[i]);
		else g[i]=a[i];
		ed[i].push_back(a[i]);
	}

	for(int re i=1;i<=m;++i){
		b[i]=getint();
		if(b[i]<=P-6)isbad[b[i]]=true;
		badprimes.insert(b[i]);
	}

	linear_sieves();
	for(int re i=1;i<=n;++i)ans+=F(a[i]);

	for(int re i=n;i;--i){
		int now=g[i];
		suf[i]=suf[i+1]+F(a[i]);
		int sum=suf[i+1];
		for(int re j=i;j;--j)sum+=F(a[j]/now),ed[j].push_back(a[j]/now);
		ans=max(ans,sum);
	}
	memset(maxn,-0x3f,sizeof maxn);
	for(int re i=ed[1].size()-1;~i;--i){
		sum[1][i]=F(ed[1][i]);maxn[1][i]=max(sum[1][i],maxn[1][i+1]);
	}

	for(int re i=2;i<=n;++i){
		for(int re j=ed[i].size()-1;~j;--j){
			sum[i][j]=F(ed[i][j])+maxn[i-1][j];
			maxn[i][j]=max(maxn[i][j+1],sum[i][j]);
		}
	}
	for(int re i=ed[n].size()-1;~i;--i){
		ans=max(ans,maxn[n][i]);
	}

	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
	re int num;
	re char c;
	while(!isdigit(c=gc()));num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return num;
}

inline int gcd(int a,int b){
	int tmp;
	while(b){
		tmp=a-a/b*b;
		a=b;
		b=tmp;
	}
	return a;
}

cs int P=1000006;
bool mark[P];
int prime[P],pcnt;
bool isbad[P];
int f[P];
set<int> badprimes;
inline void linear_sieves(int len=P-6){
	for(int re i=2;i<=len;++i){
		if(!mark[i])prime[++pcnt]=i,f[i]=isbad[i]?-1:1;
		for(int re j=1;j<=pcnt&&i*prime[j]<=len;++j){
			mark[i*prime[j]]=true;
			f[i*prime[j]]=f[i]+((isbad[prime[j]])?-1:1);
			if(i%prime[j]==0)break;
		}
	}
}

inline bool isbadprime(int a){
	if(a<=P-6)return isbad[a];
	else return badprimes.find(a)!=badprimes.end();
}

tr1::unordered_map<int,int> FF;
inline int F(int a){
	if(a<=P-6)return f[a];
	else if(FF.find(a)!=FF.end())return FF[a];
	int pos=0;
	for(int re i=1;i<=pcnt&&prime[i]*prime[i]<=a;++i)if(a%prime[i]==0){
		pos=i;break;
	}
	if(pos)return FF[a]=(isbad[prime[pos]]?-1:1)+F(a/prime[pos]);
	else return FF[a]=isbadprime(a)?-1:1;
}

cs int N=2003;
int n,m;
int a[N],g[N],b[N];
vector<int> ed[N];
int suf[N];
int ans;
int sum[N][N];
int maxn[N][N];

signed main(){
	freopen("cup.in","r",stdin);
	freopen("cup.out","w",stdout);
	n=getint();
	m=getint();
	for(int re i=1;i<=n;++i){
		a[i]=getint();
		if(i>1)g[i]=gcd(g[i-1],a[i]);
		else g[i]=a[i];
		ed[i].push_back(a[i]);
	}

	for(int re i=1;i<=m;++i){
		b[i]=getint();
		if(b[i]<=P-6)isbad[b[i]]=true;
		badprimes.insert(b[i]);
	}

	linear_sieves();
	for(int re i=1;i<=n;++i)ans+=F(a[i]);

	for(int re i=n;i;--i){
		int now=g[i];
		suf[i]=suf[i+1]+F(a[i]);
		int sum=suf[i+1];
		for(int re j=i;j;--j)sum+=F(a[j]/now),ed[j].push_back(a[j]/now);
		ans=max(ans,sum);
	}
	memset(maxn,-0x3f,sizeof maxn);
	for(int re i=ed[1].size()-1;~i;--i){
		sum[1][i]=F(ed[1][i]);maxn[1][i]=max(sum[1][i],maxn[1][i+1]);
	}

	for(int re i=2;i<=n;++i){
		for(int re j=ed[i].size()-1;~j;--j){
			sum[i][j]=F(ed[i][j])+maxn[i-1][j];
			maxn[i][j]=max(maxn[i][j+1],sum[i][j]);
		}
	}
	for(int re i=ed[n].size()-1;~i;--i){
		ans=max(ans,maxn[n][i]);
	}

	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
	re int num;
	re char c;
	while(!isdigit(c=gc()));num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return num;
}

inline int gcd(int a,int b){
	int tmp;
	while(b){
		tmp=a-a/b*b;
		a=b;
		b=tmp;
	}
	return a;
}

cs int P=1000006;
bool mark[P];
int prime[P],pcnt;
bool isbad[P];
int f[P];
set<int> badprimes;
inline void linear_sieves(int len=P-6){
	for(int re i=2;i<=len;++i){
		if(!mark[i])prime[++pcnt]=i,f[i]=isbad[i]?-1:1;
		for(int re j=1;j<=pcnt&&i*prime[j]<=len;++j){
			mark[i*prime[j]]=true;
			f[i*prime[j]]=f[i]+((isbad[prime[j]])?-1:1);
			if(i%prime[j]==0)break;
		}
	}
}

inline bool isbadprime(int a){
	if(a<=P-6)return isbad[a];
	else return badprimes.find(a)!=badprimes.end();
}

tr1::unordered_map<int,int> FF;
inline int F(int a){
	if(a<=P-6)return f[a];
	else if(FF.find(a)!=FF.end())return FF[a];
	int pos=0;
	for(int re i=1;i<=pcnt&&prime[i]*prime[i]<=a;++i)if(a%prime[i]==0){
		pos=i;break;
	}
	if(pos)return FF[a]=(isbad[prime[pos]]?-1:1)+F(a/prime[pos]);
	else return FF[a]=isbadprime(a)?-1:1;
}

cs int N=5003;
int n,m;
int a[N],g[N];
vector<int> ed[N];
int suf;
int ans;
int maxn[N][N];

signed main(){
	n=getint();
	m=getint();
	for(int re i=1;i<=n;++i){
		a[i]=getint();
		if(i>1)g[i]=gcd(g[i-1],a[i]);
		else g[i]=a[i];
		ed[i].push_back(a[i]);
	}

	for(int re i=1;i<=m;++i){
		int b=getint();
		if(b<=P-6)isbad[b]=true;
		badprimes.insert(b);
	}

	linear_sieves();
	for(int re i=1;i<=n;++i)ans+=F(a[i]);

	for(int re i=n;i;--i){
		int now=g[i];
		int sum=suf;
		suf+=F(a[i]);
		for(int re j=i;j;--j)sum+=F(a[j]/now),ed[j].push_back(a[j]/now);
		ans=max(ans,sum);
	}
	memset(maxn,-0x3f,sizeof maxn);
	for(int re i=ed[1].size()-1;~i;--i){
		maxn[1][i]=max(F(ed[1][i]),maxn[1][i+1]);
	}

	for(int re i=2;i<=n;++i){
		for(int re j=ed[i].size()-1;~j;--j){
			maxn[i][j]=max(maxn[i][j+1],F(ed[i][j])+maxn[i-1][j]);
		}
	}
	for(int re i=ed[n].size()-1;~i;--i){
		ans=max(ans,maxn[n][i]);
	}

	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
	re int num;
	re char c;
	while(!isdigit(c=gc()));num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return num;
}

inline int gcd(int a,int b){
	int tmp;
	while(b){
		tmp=a-a/b*b;
		a=b;
		b=tmp;
	}
	return a;
}

cs int P=1000006;
bool mark[P];
int prime[P],pcnt;
bool isbad[P];
int f[P];
set<int> badprimes;
inline void linear_sieves(int len=P-6){
	for(int re i=2;i<=len;++i){
		if(!mark[i])prime[++pcnt]=i,f[i]=isbad[i]?-1:1;
		for(int re j=1;j<=pcnt&&i*prime[j]<=len;++j){
			mark[i*prime[j]]=true;
			f[i*prime[j]]=f[i]+((isbad[prime[j]])?-1:1);
			if(i%prime[j]==0)break;
		}
	}
}

inline bool isbadprime(int a){
	if(a<=P-6)return isbad[a];
	else return badprimes.find(a)!=badprimes.end();
}

tr1::unordered_map<int,int> FF;
inline int F(int a){
	if(a<=P-6)return f[a];
	else if(FF.find(a)!=FF.end())return FF[a];
	int pos=0;
	for(int re i=1;i<=pcnt&&prime[i]*prime[i]<=a;++i)if(a%prime[i]==0){
		pos=i;break;
	}
	if(pos)return FF[a]=(isbad[prime[pos]]?-1:1)+F(a/prime[pos]);
	else return FF[a]=isbadprime(a)?-1:1;
}

cs int N=2003;
int n,m;
int a[N],g[N],b[N];
vector<int> ed[N];
int suf[N];
int ans;
int sum[N][N];
int maxn[N][N];

signed main(){
	n=getint();
	m=getint();
	for(int re i=1;i<=n;++i){
		a[i]=getint();
		if(i>1)g[i]=gcd(g[i-1],a[i]);
		else g[i]=a[i];
		ed[i].push_back(a[i]);
	}

	for(int re i=1;i<=m;++i){
		b[i]=getint();
		if(b[i]<=P-6)isbad[b[i]]=true;
		badprimes.insert(b[i]);
	}

	linear_sieves();
	for(int re i=1;i<=n;++i)ans+=F(a[i]);

	for(int re i=n;i;--i){
		int now=g[i];
		suf[i]=suf[i+1]+F(a[i]);
		int sum=suf[i+1];
		for(int re j=i;j;--j)sum+=F(a[j]/now),ed[j].push_back(a[j]/now);
		ans=max(ans,sum);
	}
	memset(maxn,-0x3f,sizeof maxn);
	for(int re i=ed[1].size()-1;~i;--i){
		sum[1][i]=F(ed[1][i]);maxn[1][i]=max(sum[1][i],maxn[1][i+1]);
	}

	for(int re i=2;i<=n;++i){
		for(int re j=ed[i].size()-1;~j;--j){
			sum[i][j]=F(ed[i][j])+maxn[i-1][j];
			maxn[i][j]=max(maxn[i][j+1],sum[i][j]);
		}
	}
	for(int re i=ed[n].size()-1;~i;--i){
		ans=max(ans,maxn[n][i]);
	}

	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
	re int num;
	re char c;
	while(!isdigit(c=gc()));num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return num;
}

inline int gcd(int a,int b){
	int tmp;
	while(b){
		tmp=a-a/b*b;
		a=b;
		b=tmp;
	}
	return a;
}

cs int P=1000006;
bool mark[P];
int prime[P],pcnt;
bool isbad[P];
int f[P];
set<int> badprimes;
inline void linear_sieves(int len=P-6){
	for(int re i=2;i<=len;++i){
		if(!mark[i])prime[++pcnt]=i,f[i]=isbad[i]?-1:1;
		for(int re j=1;j<=pcnt&&i*prime[j]<=len;++j){
			mark[i*prime[j]]=true;
			f[i*prime[j]]=f[i]+((isbad[prime[j]])?-1:1);
			if(i%prime[j]==0)break;
		}
	}
}

inline bool isbadprime(int a){
	if(a<=P-6)return isbad[a];
	else return badprimes.find(a)!=badprimes.end();
}

tr1::unordered_map<int,int> FF;
inline int F(int a){
	if(a<=P-6)return f[a];
	else if(FF.find(a)!=FF.end())return FF[a];
	int pos=0;
	for(int re i=1;i<=pcnt&&prime[i]*prime[i]<=a;++i)if(a%prime[i]==0){
		pos=i;break;
	}
	if(pos)return FF[a]=(isbad[prime[pos]]?-1:1)+F(a/prime[pos]);
	else return FF[a]=isbadprime(a)?-1:1;
}

cs int N=5003;
int a[N],b[N];
int n,m;
int ans;

signed main(){
	n=getint();
	m=getint();
	for(int re i=1;i<=n;++i)a[i]=getint();
	for(int re i=1;i<=m;++i){
		int b=getint();
		if(b<=P-6)isbad[b]=true;
		badprimes.insert(b);
	}
	linear_sieves();
	for(int re i=1;i<=n;++i){
		ans+=F(a[i]);
		if(i^1)a[i]=gcd(a[i],a[i-1]);
		b[i]=-F(a[i]);
	}
	int now=0;
	for(int re i=n;i;--i){
		if(b[i]-now>0)ans+=i*(b[i]-now),now=b[i];
	}
	cout<<ans;
	return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef int ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    map<ll, ll> bad;
    set<ll> b;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
        b.insert(el);
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        for (auto p : b)
        {
            ll len = 0;
            if (temp % p == 0)
            {
                while (temp % p == 0)
                {
                    --ans;
                    ++len;
                    temp /= p;
                }
            }
        }
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                while (temp % i == 0)
                {
                    ++ans;
                    temp /= i;
                }
            }
        }
        if (temp != 1)
            ++ans;
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef int ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // fast
    ll n, m;
    scanf("%d%d", &n, &m);
    vl a(n), b(m);
    loop(i, n)   scanf("%d", &a[i]);
    unordered_map<ll, ll> bad;
    loop(i, m)   scanf("%d", &b[i]);

    loop(i, m)   bad[b[i]] = 1;

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        for (ll j = 2; j * j <= g; ++j)
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        for (ll i = 2; i * i <= temp; ++i)
        {
            if (temp % i == 0)
            {
                ll cnt = 0;
                while (temp % i == 0)
                {
                    ++cnt;
                    temp /= i;
                }
                if (bad[i])
                    ans -= cnt;
                else
                    ans += cnt;
            }
        }
        if (temp != 1)
        {
            if (bad[temp])
                --ans;
            else
                ++ans;
        }
    }

    printf("%d\n", ans);

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    unordered_map<ll, ll> bad;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        for (ll j = 2; j * j <= g; ++j)
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        for (ll i = 2; i * i <= temp; ++i)
        {
            if (temp % i == 0)
            {
                ll cnt = 0;
                while (temp % i == 0)
                {
                    ++cnt;
                    temp /= i;
                }
                if (bad[i])
                    ans -= cnt;
                else
                    ans += cnt;
            }
        }
        if (temp != 1)
        {
            if (bad[temp])
                --ans;
            else
                ++ans;
        }
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef int ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    unordered_map<ll, ll> bad;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        for (ll j = 2; j * j <= g; ++j)
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        for (ll i = 2; i * i <= temp; ++i)
        {
            if (temp % i == 0)
            {
                ll cnt = 0;
                while (temp % i == 0)
                {
                    ++cnt;
                    temp /= i;
                }
                if (bad[i])
                    ans -= cnt;
                else
                    ans += cnt;
            }
        }
        if (temp != 1)
        {
            if (bad[temp])
                --ans;
            else
                ++ans;
        }
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    map<ll, ll> bad;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        // cout << temp << END;
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                ll cnt = 0;
                while (temp % i == 0)
                {
                    ++cnt;
                    temp /= i;
                }
                if (bad[i])
                    ans -= cnt;
                else
                    ans += cnt;
            }
        }
        if (temp != 1)
        {
            if (bad[temp])
                --ans;
            else
                ++ans;
        }
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    unordered_map<ll, ll> bad;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        // cout << temp << END;
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                ll cnt = 0;
                while (temp % i == 0)
                {
                    ++cnt;
                    temp /= i;
                }
                if (bad[i])
                    ans -= cnt;
                else
                    ans += cnt;
            }
        }
        if (temp != 1)
        {
            if (bad[temp])
                --ans;
            else
                ++ans;
        }
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    set<ll> b;
    loop(i, m)
    {
        ll el;
        cin >> el;
        b.insert(el);
    }

    ll ans = 0;
    map<ppl, ll> cnt;
    loop(i, n)
    {
        ll temp = a[i];
        for (auto p : b)
        {
            ll len = 0;
            if (temp % p == 0)
            {
                while (temp % p == 0)
                {
                    --ans;
                    ++len;
                    temp /= p;
                }
                cnt[mp(p, i)] = len;
            }
        }
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                while (temp % i == 0)
                {
                    ++ans;
                    temp /= i;
                }
            }
        }
        if (temp != 1)
            ++ans;
    }

    for (auto p : b)
    {
        ll curr = cnt[mp(p, 0)];
        loop(i, n)
        {
            curr = min(cnt[mp(p, i)], curr);
            ans += curr;
        }
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    map<ll, ll> bad;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[i]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(i, n)
    {
        ll temp = a[i];
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                ll cnt = 0;
                while (temp % i == 0)
                {
                    ++cnt;
                    temp /= i;
                }
                if (bad[i])
                    ans -= cnt;
                else
                    ans += cnt;
            }
        }
        if (temp != 1)
        {
            if (bad[temp])
                --ans;
            else
                ++ans;
        }
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef int ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    map<ll, ll> bad;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        // cout << temp << END;
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                ll cnt = 0;
                while (temp % i == 0)
                {
                    ++cnt;
                    temp /= i;
                }
                if (bad[i])
                    ans -= cnt;
                else
                    ans += cnt;
            }
        }
        if (temp != 1)
        {
            if (bad[temp])
                --ans;
            else
                ++ans;
        }
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    map<ll, ll> bad;
    set<ll> b;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
        b.insert(el);
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[i]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(i, n)
    {
        ll temp = a[i];
        for (auto p : b)
        {
            ll len = 0;
            if (temp % p == 0)
            {
                while (temp % p == 0)
                {
                    --ans;
                    ++len;
                    temp /= p;
                }
            }
        }
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                while (temp % i == 0)
                {
                    ++ans;
                    temp /= i;
                }
            }
        }
        if (temp != 1)
            ++ans;
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    map<ll, ll> bad;
    set<ll> b;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
        b.insert(el);
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[i]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[i] /= el;
        }
    }

    loop(i, n)
    {
        ll temp = a[i];
        for (auto p : b)
        {
            ll len = 0;
            if (temp % p == 0)
            {
                while (temp % p == 0)
                {
                    --ans;
                    ++len;
                    temp /= p;
                }
            }
        }
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                while (temp % i == 0)
                {
                    ++ans;
                    temp /= i;
                }
            }
        }
        if (temp != 1)
            ++ans;
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ain(a, n);
    map<ll, ll> bad;
    set<ll> b;
    loop(i, m)
    {
        ll el;
        cin >> el;
        bad[el] = 1;
        b.insert(el);
    }

    ll ans = 0;
    FORD(i, n - 1, 0)
    {
        ll g = a[0];
        loop(j, i + 1) g = __gcd(g, a[j]);
        ll el = g, curr = 0;
        FOR(j, 2, sqrt(g))
        {
            if (g % j == 0)
            {
                ll cnt = 0;
                while (g % j == 0)
                {
                    ++cnt;
                    g /= j;
                }
                if (bad[j])
                    curr -= cnt;
                else
                    curr += cnt;
            }
        }
        if (g != 1)
        {
            if (bad[g])
                --curr;
            else
                ++curr;
        }
        if (curr < 0)
        {
            loop(j, i + 1) a[j] /= el;
        }
    }

    loop(j, n)
    {
        ll temp = a[j];
        for (auto p : b)
        {
            ll len = 0;
            if (temp % p == 0)
            {
                while (temp % p == 0)
                {
                    --ans;
                    ++len;
                    temp /= p;
                }
            }
        }
        FOR(i, 2, sqrt(temp))
        {
            if (temp % i == 0)
            {
                while (temp % i == 0)
                {
                    ++ans;
                    temp /= i;
                }
            }
        }
        if (temp != 1)
            ++ans;
    }

    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 5002;
int Arr[N];
int pre[N][N];
int cnt[N],bad[N],gcd[N];
int p[35000];
int n,m;
vector<int> pr;
pair<int,int> f(int e) {
    int cnt = 0;
    int z = e;
    int cnt2 = 0;
    int ind = 0;
    for(int j =0;j<pr.size() && sqrt(e) >= pr[j];j++) {
            int v = 0;
            while(e%pr[j] ==0) {
                v++;
                e/=pr[j];
            }
            cnt+=v;
            if(bad[ind] == pr[j]) {
                cnt2+=v;
                ind++;
            }
        }
    if(e > 1) cnt++;
    for(int i =1;i<=m;i++) {
        if(e%bad[i]==0) {
            cnt2++;
            break;
        }
    }
    return {cnt2,cnt-cnt2};
}
int main()
{
    ios_base::sync_with_stdio(false);
    for(int i =2;i<35000;i++) {
        if(p[i]) continue;
        else pr.push_back(i);
        for(int j =i*2;j<=35000;j+=i)p[j] = 1;
    }
    cin >> n >> m;
    for(int i =1;i<=n;i++) {
        cin >> Arr[i];
        gcd[i] = __gcd(gcd[i-1],Arr[i]);
    }
    for(int i=1;i<=m;i++) cin >> bad[i];
    int curr = 1;
    for(int i =n;i>0;i--) {
        pair<int,int> x = f(gcd[i]/curr);
        if(x.first > x.second) {
            curr*= gcd[i]/curr;
        }
        Arr[i]/=curr;
    }
    int ans = 0;
    for(int i =1;i<=n;i++) {
        pair<int,int> a = f(Arr[i]);
        ans+=a.second - a.first;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 5002;
int Arr[N];
int pre[N][N];
int cnt[N],bad[N],gcd[N];
int p[35000];
int n,m;
vector<int> pr;
pair<int,int> f(int e) {
    int cnt = 0;
    int z = e;
    int cnt2 = 0;
    int ind = 0;
    for(int j =0;j<pr.size() && sqrt(e) >= pr[j];j++) {
            int v = 0;
            while(e%pr[j] ==0) {
                v++;
                e/=pr[j];
            }
            cnt+=v;
            if(bad[ind] == pr[j]) {
                cnt2+=v;
                ind++;
            }
        }
    if(e > 1) cnt++;
    for(int i =1;i<=m;i++) {
        if(e%bad[i]==0) {
            cnt2++;
            break;
        }
    }
    return {cnt2,cnt-cnt2};
}
int main()
{
    ios_base::sync_with_stdio(false);
    for(int i =2;i<35000;i++) {
        if(p[i]) continue;
        else pr.push_back(i);
        for(int j =i*2;j<35000;j+=i)p[j] = 1;
    }
    cin >> n >> m;
    for(int i =1;i<=n;i++) {
        cin >> Arr[i];
        gcd[i] = __gcd(gcd[i-1],Arr[i]);
    }
    for(int i=1;i<=m;i++) cin >> bad[i];
    int curr = 1;
    for(int i =n;i>0;i--) {
        pair<int,int> x = f(gcd[i]/curr);
        if(x.first > x.second) {
            curr*= gcd[i]/curr;
        }
        Arr[i]/=curr;
    }
    int ans = 0;
    for(int i =1;i<=n;i++) {
        pair<int,int> a = f(Arr[i]);
        ans+=a.second - a.first;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 5002;
int Arr[N];
int pre[N][N];
int cnt[N],bad[N],gcd[N];
    int n,m;
pair<int,int> f(int e) {
    int cnt = 0;
    int z = e;
    for(int j =2;j<=sqrt(e);j++) {
            while(e%j ==0) {
                cnt++;
                e/=j;
            }
        }
    if(e > 1) cnt++;
    int cnt2 = 0;
    for(int j =1;j<=m;j++) {
        while(z%bad[j]==0) {
            cnt2++;
            z/=bad[j];
        }
    }
    return {cnt2,cnt-cnt2};
}
int main()
{
    cin >> n >> m;
    for(int i =1;i<=n;i++) {
        cin >> Arr[i];
        gcd[i] = __gcd(gcd[i-1],Arr[i]);
    }
    for(int i=1;i<=m;i++) cin >> bad[i];
    int curr = 1;
    for(int i =n;i>0;i--) {
        pair<int,int> x = f(gcd[i]/curr);
        if(x.first > x.second) {
            curr*= gcd[i]/curr;
        }
        Arr[i]/=curr;
    }
    int ans = 0;
    for(int i =1;i<=n;i++) {
        pair<int,int> a = f(Arr[i]);
        ans+=a.second - a.first;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 5002;
int Arr[N];
int pre[N][N];
int cnt[N],bad[N],gcd[N];
int p[35000];
int n,m;
vector<int> pr;
pair<int,int> f(int e) {
    int cnt = 0;
    int z = e;
    int cnt2 = 0;
    int ind = 1;
    for(int j =0;j<pr.size() && sqrt(e) >= pr[j];j++) {
            int v = 0;
            while(e%pr[j] ==0) {
                v++;
                e/=pr[j];
            }
            cnt+=v;
            if(bad[ind] == pr[j]) {
                cnt2+=v;
                ind++;
            }
        }
    if(e > 1) cnt++;
    for(int i =1;i<=m;i++) {
        if(e%bad[i]==0) {
            cnt2++;
            break;
        }
    }
    return {cnt2,cnt-cnt2};
}
int main()
{
    ios_base::sync_with_stdio(false);
    for(int i =2;i<35000;i++) {
        if(p[i]) continue;
        else pr.push_back(i);
        for(int j =i*2;j<35000;j+=i)p[j] = 1;
    }
    cin >> n >> m;
    for(int i =1;i<=n;i++) {
        cin >> Arr[i];
        gcd[i] = __gcd(gcd[i-1],Arr[i]);
    }
    for(int i=1;i<=m;i++) cin >> bad[i];
    int curr = 1;
    for(int i =n;i>0;i--) {
        pair<int,int> x = f(gcd[i]/curr);
        if(x.first > x.second) {
            curr*= gcd[i]/curr;
        }
        Arr[i]/=curr;
    }
    int ans = 0;
    for(int i =1;i<=n;i++) {
        pair<int,int> a = f(Arr[i]);
        ans+=a.second - a.first;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 5002;
int Arr[N];
int pre[N][N];
int cnt[N],bad[N],gcd[N];
int p[35000];
int n,m;
vector<int> pr;
pair<int,int> f(int e) {
    int cnt = 0;
    int z = e;
    int cnt2 = 0;
    int ind = 1;
    for(int j =0;j<pr.size() && sqrt(e) >= pr[j];j++) {
            int v = 0;
            while(e%pr[j] ==0) {
                v++;
                e/=pr[j];
            }
            cnt+=v;
            if(bad[ind] == pr[j]) {
                cnt2+=v;
                ind++;
            }
        }
    if(e > 1) cnt++;
    for(int i =1;i<=m;i++) {
        if(e%bad[i]==0) {
            cnt2++;
            break;
        }
    }
    return {cnt2,cnt-cnt2};
}
int main()
{
    ios_base::sync_with_stdio(false);
    for(int i =2;i<35000;i++) {
        if(p[i]) continue;
        else pr.push_back(i);
        for(int j =i*2;j<35000;j+=i)p[j] = 1;
    }
    cin >> n >> m;
    for(int i =1;i<=n;i++) {
        cin >> Arr[i];
        gcd[i] = __gcd(gcd[i-1],Arr[i]);
    }
    for(int i=1;i<=m;i++) cin >> bad[i];
    int curr = 1;
    for(int i =n;i>0;i--) {
        pair<int,int> x = f(gcd[i]/curr);
        if(x.first > x.second) {
            curr*= gcd[i]/curr;
        }
        Arr[i]/=curr;
    }
    int ans = 0;
    for(int i =1;i<=n;i++) {
        pair<int,int> a = f2(Arr[i]);
        ans+=a.second - a.first;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
vector<ll> p[5005];
map<ll,ll> d;
ll a[5005],b[5006],c[5005];
int main(){
    ll n,m;cin>>n>>m;
    for(ll i=1;i<=n;i++){
        cin>>a[i];ll x=a[i];
        for(ll j=2;j*j<=x;j++){
            while(x%j==0) x/=j,p[i].push_back(j);
        }
        if(x>1) p[i].push_back(x);
        c[i]=__gcd(a[i],c[i-1]);
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];d[b[i]]=1;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        for(auto j:p[i]){
            if(d[j]) ans--;
            else ans++;
        }
    }

    ll now=1;
    for(ll i=n;i>=1;i--){
        if(c[i]/now==1) continue;
        ll x=c[i]/now,num=0;
        for(ll j=2;j*j<=x;j++){
            while(x%j==0){
                x/=j;
                if(d[j]) num--;
                else num++;
            }
        }
        if(x>1){
            if(d[x]) num--;
            else num++;
        }
        if(num>0) continue;
        else{
            ans-=num*i;
            now=c[i];
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
map<ll,ll> d;
ll a[5005],b[5006],c[5005];
ll solve(ll x){
    if(d[x]||x==1) return d[x];
    for(ll j=2;j*j<=x;j++){
        if(x%j==0){
            d[x]=solve(x/j)+solve(j);return d[x];
        }
    }
    d[x]=1;return 1;
}
int main(){
    ll n,m;cin>>n>>m;
    for(ll i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        c[i]=__gcd(c[i-1],a[i]);
    }
    d[1]=0;
    for(int i=1;i<=m;i++){
        scanf("%lld",&b[i]);d[b[i]]=-1;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=solve(a[i]);
    }
    ll now=1;
    for(ll i=n;i>=1;i--){
        if(c[i]/now==1) continue;
        ll x=c[i]/now,num=solve(x);
        if(num>0) continue;
        else{
            ans-=num*i;
            now=c[i];
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
vector<ll> p[5005];
map<ll,ll> d;
ll a[5005],b[5006],c[5005];
int main(){
    ll n,m;cin>>n>>m;
    for(ll i=1;i<=n;i++){
        cin>>a[i];ll x=a[i];
        for(ll j=2;j*j<=x;j++){
            while(x%j==0) x/=j,p[i].push_back(j);
        }
        if(x>1) p[i].push_back(x);
        c[i]=__gcd(a[i],c[i-1]);
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];d[b[i]]=1;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        for(auto j:p[i]){
            if(d[j]) ans--;
            else ans++;
        }
    }
    ll now=1;
    for(ll i=n;i>=1;i--){
        if(c[i]/now==1) continue;
        ll x=c[i]/now,num=0;
        for(ll j=2;j*j<=x;j++){
            while(x%j==0){
                x/=j;
                if(d[j]) num--;
                else num++;
            }
        }
        if(x>1){
            if(d[x]) num--;
            else num++;
        }
        if(num>0) continue;
        else{
            ans-=num*i;
            now*=c[i];
        }
    }
    cout<<ans<<endl;
}


//Author : Ayush Jain

#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=5e3 + 5;
const int M=1e5 + 5;
map <int,int> b;
int fun(int n)
{
	int num=n;
	int ans=0;
	for(int i=2;i*i <= num;i++){
		if(num%i==0){
			bool bad=false;
			if(b[i]) bad=true;
			while(num%i==0){
				if(bad) ans--;
				else ans++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b[num]) ans--;
		else ans++;
	}
	return ans;
}

bool check(int n)
{
	int num=n;
	int ba=0,go=0;
	for(int i=2;i*i <= num;i++){
		if(num%i==0){
			bool bad=false;
			if(b[i]) bad=true;
			while(num%i==0){
				if(bad) ba++;
				else go++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b[num]) ba++;
		else go++;
	}
	return ba>=go ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m,i,a[N],g[N];
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<m;i++){
		int k;
		cin>>k;
		b[k]++;
	}
	g[0]=a[0];
	for(i=1;i<n;i++){
		g[i]=__gcd(g[i-1],a[i]);
	}
	int mul=1;
	int arr[N];
	for(i=0;i<N;i++){
		arr[i]=-1;
	}
	for(i=n-1;i>=0;i--){
		int foo=g[i];
		foo/=mul;
		if(check(foo)){
			mul*=foo;
			arr[i]=mul;
		}
	}
	mul=-1;
	for(i=n-1;i>=0;i--){
		if(arr[i]!=-1) mul=arr[i];
		if(mul!=-1){
			a[i]/=mul;
		}
	}
	int ans=0;
	for(i=0;i<n;i++){
		ans+=fun(a[i]);
	}
	cout<<ans<<endl;

	return 0;
}


//Author : Ayush Jain

#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=5e3 + 5;
const int M=1e5 + 5;
map <int,int> b;
int fun(int n)
{
	int num=n;
	int ans=0;
	for(int i=2;i<=(int)(sqrt(num));i++){
		if(num%i==0){
			bool bad=false;
			if(b[i]) bad=true;
			while(num%i==0){
				if(bad) ans--;
				else ans++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b[num]) ans--;
		else ans++;
	}
	return ans;
}

bool check(int n)
{
	int num=n;
	int ba=0,go=0;
	for(int i=2;i<=(int)(sqrt(num));i++){
		if(num%i==0){
			bool bad=false;
			if(b[i]) bad=true;
			while(num%i==0){
				if(bad) ba++;
				else go++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b[num]) ba++;
		else go++;
	}
	return ba>=go ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m,i,a[N],g[N];
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<m;i++){
		int k;
		cin>>k;
		b[k]++;
	}
	g[0]=a[0];
	for(i=1;i<n;i++){
		g[i]=__gcd(g[i-1],a[i]);
	}
	int mul=1;
	int arr[N];
	for(i=0;i<N;i++){
		arr[i]=-1;
	}
	for(i=n-1;i>=0;i--){
		int foo=g[i];
		foo/=mul;
		if(check(foo)){
			mul*=foo;
			arr[i]=mul;
		}
	}
	mul=-1;
	for(i=n-1;i>=0;i--){
		if(arr[i]!=-1) mul=arr[i];
		if(mul!=-1){
			a[i]/=mul;
		}
	}
	int ans=0;
	for(i=0;i<n;i++){
		ans+=fun(a[i]);
	}
	cout<<ans<<endl;

	return 0;
}


//Author : Ayush Jain

#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=5e3 + 5;
const int M=1e5 + 5;
set <int> b;
ll fun(ll n)
{
	ll num=n;
	ll ans=0;
	for(ll i=2;i<=(ll)(sqrt(n));i++){
		if(num%i==0){
			bool bad=false;
			if(b.count(i)) bad=true;
			while(num%i==0){
				if(bad) ans--;
				else ans++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b.count(num)) ans--;
		else ans++;
	}
	return ans;
}

bool check(int n)
{
	int num=n;
	int ba=0,go=0;
	for(int i=2;i<=(int)(sqrt(n));i++){
		if(num%i==0){
			bool bad=false;
			if(b.count(i)) bad=true;
			while(num%i==0){
				if(bad) ba++;
				else go++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b.count(num)) ba++;
		else go++;
	}
	return ba>=go ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m,i,a[N],g[N];
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<m;i++){
		int k;
		cin>>k;
		b.insert(k);
	}
	g[0]=a[0];
	for(i=1;i<n;i++){
		g[i]=__gcd(g[i-1],a[i]);
	}
	int mul=1;
	int arr[N];
	for(i=0;i<N;i++){
		arr[i]=-1;
	}
	for(i=n-1;i>=0;i--){
		int foo=g[i];
		foo/=mul;
		if(check(foo)){
			mul*=foo;
			arr[i]=mul;
		}
	}
	mul=-1;
	for(i=n-1;i>=0;i--){
		if(arr[i]!=-1) mul=arr[i];
		if(mul!=-1){
			a[i]/=mul;
		}
	}
	ll ans=0;
	for(i=0;i<n;i++){
		ans+=fun((ll)a[i]);
	}
	cout<<ans<<endl;

	return 0;
}


//Author : Ayush Jain

#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=5e3 + 5;
const int M=1e5 + 5;
map <int,int> b;
int fun(ll n)
{
	int num=n;
	int ans=0;
	for(int i=2;i<=(int)(sqrt(n));i++){
		if(num%i==0){
			bool bad=false;
			if(b[i]) bad=true;
			while(num%i==0){
				if(bad) ans--;
				else ans++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b[num]) ans--;
		else ans++;
	}
	return ans;
}

bool check(int n)
{
	int num=n;
	int ba=0,go=0;
	for(int i=2;i<=(int)(sqrt(n));i++){
		if(num%i==0){
			bool bad=false;
			if(b[i]) bad=true;
			while(num%i==0){
				if(bad) ba++;
				else go++;
				num/=i;
			}
		}
	}
	if(num>1){
		if(b[num]) ba++;
		else go++;
	}
	return ba>=go ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m,i,a[N],g[N];
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<m;i++){
		int k;
		cin>>k;
		b[k]++;
	}
	g[0]=a[0];
	for(i=1;i<n;i++){
		g[i]=__gcd(g[i-1],a[i]);
	}
	int mul=1;
	int arr[N];
	for(i=0;i<N;i++){
		arr[i]=-1;
	}
	for(i=n-1;i>=0;i--){
		int foo=g[i];
		foo/=mul;
		if(check(foo)){
			mul*=foo;
			arr[i]=mul;
		}
	}
	mul=-1;
	for(i=n-1;i>=0;i--){
		if(arr[i]!=-1) mul=arr[i];
		if(mul!=-1){
			a[i]/=mul;
		}
	}
	int ans=0;
	for(i=0;i<n;i++){
		ans+=fun(a[i]);
	}
	cout<<ans<<endl;

	return 0;
}