#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
using namespace std;
const int N = 5005;
ll n, m, gcd, f[N], dp[N][N], a[N], res = -1e15, b[N];
ll calc(ll x)
{
	ll res = 0;
	for(int i = 1; i <= m; i ++)
		while(x % b[i] == 0){
			res --;
			x /= b[i];
		}
	for(int i = 2; i * i <= x; i ++)
		while(x % i == 0){
			res ++;
			x /= i;
		}
	if(x > 1) res ++;
	return res;
}
int main()
{
//	freopen(".inp", "r", stdin);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= m; i ++) cin >> b[i];
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n + 1; j ++) dp[i][j] = -1e15;
	dp[n][n + 1] = 0;
	for(int i = 1; i <= n; i ++){
		dp[n][n + 1] += calc(a[i]);
		gcd = __gcd(gcd, a[i]);
		f[i] = calc(gcd);
	}
	dp[n][n] = dp[n][n + 1] - n * f[n];
	for(int i = n; i > 1; i --)
		for(int j = n + 1; j >= i; j --){
			dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
			dp[i - 1][i - 1] = max(dp[i - 1][i - 1], dp[i][j] - (i - 1) * (f[i - 1] - f[j]));
		}
	for(int i = 1; i <= n + 1; i ++) res = max(res, dp[1][i]);
	cout << res;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
using namespace std;
const int N = 5005;
ll n, m, gcd, f[N], dp[N][N], a[N], res = -1e9, b[N];
ll calc(ll x)
{
	ll res = 0;
	for(int i = 1; i <= m; i ++)
		while(x % b[i] == 0){
			res --;
			x /= b[i];
		}
	for(int i = 2; i * i <= x; i ++)
		while(x % i == 0){
			res ++;
			x /= i;
		}
	if(x > 1) res ++;
	return res;
}
int main()
{
//	freopen(".inp", "r", stdin);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= m; i ++) cin >> b[i];
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n + 1; j ++) dp[i][j] = -1e15;
	dp[n][n + 1] = 0;
	for(int i = 1; i <= n; i ++){
		dp[n][n + 1] += calc(a[i]);
		gcd = __gcd(gcd, a[i]);
		f[i] = calc(gcd);
	}
	for(int i = n; i > 1; i --)
		for(int j = n + 1; j >= i; j --){
			dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
			dp[i - 1][j - 1] = max(dp[i - 1][j - 1], dp[i][j] - (i - 1) * (f[i - 1] - f[j]));
		}
	for(int i = 1; i <= n + 1; i ++) res = max(res, dp[1][i]);
	cout << res;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
using namespace std;
const int N = 5005;
ll n, m, gcd, f[N], dp[N][N], a[N], res = -1e9, b[N];
ll calc(ll x)
{
	ll res = 0;
	for(int i = 1; i <= m; i ++)
		while(x % b[i] == 0){
			res --;
			x /= b[i];
		}
	for(int i = 2; i * i <= x; i ++)
		while(x % i == 0){
			res ++;
			x /= i;
		}
	if(x > 1) res ++;
	return res;
}
int main()
{
//	freopen(".inp", "r", stdin);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= m; i ++) cin >> b[i];
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n + 1; j ++) dp[i][j] = -1e15;
	dp[n][n + 1] = 0;
	for(int i = 1; i <= n; i ++){
		dp[n][n + 1] += calc(a[i]);
		gcd = __gcd(gcd, a[i]);
		f[i] = calc(gcd);
	}
	for(int i = n; i > 1; i --)
		for(int j = n + 1; j >= i; j --){
			dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
			dp[i - 1][j - 1] = max(dp[i - 1][j - 1], dp[i][j] - (i) * (f[i - 1] - f[j]));
		}
	for(int i = 1; i <= n + 1; i ++) res = max(res, dp[1][i]);
	cout << res;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
using namespace std;
const int N = 5005, Max = 3200;
ll n, m, gcd, f[N], dp[N][N], a[N], res = -1e15, b[N], dd[Max + 69];
vector<int> d;
ll calc(ll x)
{
	ll res = 0;
	for(int i = 1; i <= m; i ++)
		while(x % b[i] == 0){
			res --;
			x /= b[i];
		}
	for(int i : d){
		if(i * i > x) break;
		while(x % i == 0){
			res ++;
			x /= i;
		}
	}
	if(x > 1) res ++;
	return res;
}
int main()
{
//	freopen("402D.inp", "r", stdin);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for(int i = 2; i * i <= Max; i ++){
		if(dd[i]) continue;
		for(int j = i * i; j <= Max; j += i) dd[j] = 1;
	}
	for(int i = 2; i <= Max; i ++)
		if(!dd[i]) d.pb(i);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= m; i ++) cin >> b[i];
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n + 1; j ++) dp[i][j] = -1e15;
	dp[n][n + 1] = 0;
	for(int i = 1; i <= n; i ++){
		dp[n][n + 1] += calc(a[i]);
		gcd = __gcd(gcd, a[i]);
		f[i] = calc(gcd);
	}
	dp[n][n] = dp[n][n + 1] - n * f[n];
	for(int i = n; i > 1; i --)
		for(int j = n + 1; j >= i; j --){
			dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
			dp[i - 1][i - 1] = max(dp[i - 1][i - 1], dp[i][j] - (i - 1) * (f[i - 1] - f[j]));
		}
	for(int i = 1; i <= n + 1; i ++) res = max(res, dp[1][i]);
	cout << res;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
using namespace std;
const int N = 5005, Max = 32000;
ll n, m, gcd, f[N], dp[N][N], a[N], res = -1e15, b[N], dd[Max + 69];
vector<int> d;
ll calc(ll x)
{
	ll res = 0;
	for(int i = 1; i <= m; i ++)
		while(x % b[i] == 0){
			res --;
			x /= b[i];
		}
	for(int i : d){
		if(i * i > x) break;
		while(x % i == 0){
			res ++;
			x /= i;
		}
	}
	if(x > 1) res ++;
	return res;
}
int main()
{
//	freopen("402D.inp", "r", stdin);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for(int i = 2; i * i <= Max; i ++){
		if(dd[i]) continue;
		for(int j = i * i; j <= Max; j += i) dd[j] = 1;
	}
	for(int i = 2; i <= Max; i ++)
		if(!dd[i]) d.pb(i);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= m; i ++) cin >> b[i];
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n + 1; j ++) dp[i][j] = -1e15;
	dp[n][n + 1] = 0;
	for(int i = 1; i <= n; i ++){
		dp[n][n + 1] += calc(a[i]);
		gcd = __gcd(gcd, a[i]);
		f[i] = calc(gcd);
	}
	dp[n][n] = dp[n][n + 1] - n * f[n];
	for(int i = n; i > 1; i --)
		for(int j = n + 1; j >= i; j --){
			dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
			dp[i - 1][i - 1] = max(dp[i - 1][i - 1], dp[i][j] - (i - 1) * (f[i - 1] - f[j]));
		}
	for(int i = 1; i <= n + 1; i ++) res = max(res, dp[1][i]);
	cout << res;
}


/*****Enigma27*****/
#include<bits/stdc++.h>
#define start_routine clock_t begin = clock();
#define end_routine clock_t end = clock(); double elapsed_secs = double(end - begin) /CLOCKS_PER_SEC;return cerr<<"\nTime elapsed : "<<elapsed_secs<<" seconds\n",0;
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll         pair<ll int,ll int>
#define vll          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k,l,sum=0,flag=0,t,a[5005],ans=0,b[5005];
vll v[5005];
set<ll> bad;
void factor(int ind){
	ll num=a[ind],temp=a[ind];
	for(ll j=2;j*j<=num;){
		if(temp%j==0){
			 temp/=j;
			 if(bad.find(j)!=bad.end()) ans--;
			 else ans++;
		}
		else j++;
	}
	if(temp>1){
		if(bad.find(temp)!=bad.end()) ans--;
		else ans++;
	}
}
int check(int g){
	ll temp=g,tt=0;
	for(ll j=2;j*j<=g;){
		if(temp%j==0){
			temp/=j;
			if(bad.find(j)!=bad.end()) tt++;
			else tt--;
		}
		else j++;
	}
	if(temp>1){
		if(bad.find(temp)!=bad.end()) tt++;
		else tt--;
	}
	return tt;
}
int main()
{
    ios
    cin>>n>>k;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(!i) b[i]=a[i];
    	else b[i]=gcd(a[i],b[i-1]);
    }
    for(int i=0;i<k;i++) cin>>j,bad.insert(j);
    for(int i=0;i<n;i++) factor(i);
    ll hata_diya=1;
    for(int i=n-1;i>=0;i--){
    	ll benefit=check(b[i]/hata_diya);
    	if(benefit>=0){
    		hata_diya*=b[i]/hata_diya;
    		ans+=(i+1)*benefit;
    	}
    }
    return cout<<ans<<endl,0;
}


/*****Enigma27*****/
#include<bits/stdc++.h>
#define start_routine clock_t begin = clock();
#define end_routine clock_t end = clock(); double elapsed_secs = double(end - begin) /CLOCKS_PER_SEC;return cerr<<"\nTime elapsed : "<<elapsed_secs<<" seconds\n",0;
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll         pair<ll int,ll int>
#define vll          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k,l,sum=0,flag=0,t,a[5005],ans=0,b[5005];
vll v[5005];
set<ll> bad;
unordered_map<int,int> dp;
int check(int g){
	if(g==1) return 0;
	if(dp.count(g)) return dp[g];
	ll temp=g,tt=0;
	for(ll j=2;j*j<=g&&temp>1;){
		if(temp%j==0){
			temp/=j;
			if(bad.find(j)!=bad.end()) tt++;
			else tt--;
		}
		else j++;
	}
	if(temp>1){
		if(bad.find(temp)!=bad.end()) tt++;
		else tt--;
	}
	return dp[g]=tt;
}
int main()
{
    ios
    cin>>n>>k;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(!i) b[i]=a[i];
    	else b[i]=gcd(a[i],b[i-1]);
    }
    for(int i=0;i<k;i++) cin>>j,bad.insert(j);
    for(int i=0;i<n;i++) ans-=check(a[i]);
    ll hata_diya=1;
    for(int i=n-1;i>=0;i--){
    	ll benefit=check(b[i]/hata_diya);
    	if(benefit>=0){
    		hata_diya*=b[i]/hata_diya;
    		ans+=(i+1)*benefit;
    	}
    }
    return cout<<ans<<endl,0;
}


/*****Enigma27*****/
#include<bits/stdc++.h>
#define start_routine clock_t begin = clock();
#define end_routine clock_t end = clock(); double elapsed_secs = double(end - begin) /CLOCKS_PER_SEC;return cerr<<"\nTime elapsed : "<<elapsed_secs<<" seconds\n",0;
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll         pair<ll int,ll int>
#define vll          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int n,i,j,k,l,sum=0,flag=0,t,a[5005],ans=0,b[5005];
unordered_set<int> bad;
void factor(int ind){
	int num=a[ind],temp=a[ind];
	for(ll j=2;j*j<=num&&temp>1;){
		if(temp%j==0){
			 temp/=j;
			 if(bad.find(j)!=bad.end()) ans--;
			 else ans++;
		}
		else j++;
	}
	if(temp>1){
		if(bad.find(temp)!=bad.end()) ans--;
		else ans++;
	}
}
int check(int g){
	if(g==1) return 0;
	ll temp=g,tt=0;
	for(ll j=2;j*j<=g&&temp>1;){
		if(temp%j==0){
			temp/=j;
			if(bad.find(j)!=bad.end()) tt++;
			else tt--;
		}
		else j++;
	}
	if(temp>1){
		if(bad.find(temp)!=bad.end()) tt++;
		else tt--;
	}
	return tt;
}
int main()
{
    ios
    cin>>n>>k;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(!i) b[i]=a[i];
    	else b[i]=gcd(a[i],b[i-1]);
    }
    for(int i=0;i<k;i++) cin>>j,bad.insert(j);
    for(int i=0;i<n;i++) factor(i);
    ll hata_diya=1;
    for(int i=n-1;i>=0;i--){
    	ll benefit=check(b[i]/hata_diya);
    	if(benefit>=0){
    		hata_diya*=b[i]/hata_diya;
    		ans+=(i+1)*benefit;
    	}
    }
    return cout<<ans<<endl,0;
}


/*****Enigma27*****/
#include<bits/stdc++.h>
#define start_routine clock_t begin = clock();
#define end_routine clock_t end = clock(); double elapsed_secs = double(end - begin) /CLOCKS_PER_SEC;return cerr<<"\nTime elapsed : "<<elapsed_secs<<" seconds\n",0;
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pll         pair<ll int,ll int>
#define vll          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k,l,sum=0,flag=0,t,a[5005],ans=0,b[5005];
vll v[5005];
set<ll> bad;
unordered_map<int,int> dp;
void factor(int ind){
	ll num=a[ind],temp=a[ind];
	for(ll j=2;j*j<=num&&temp>1;){
		if(temp%j==0){
			 temp/=j;
			 if(bad.find(j)!=bad.end()) ans--;
			 else ans++;
		}
		else j++;
	}
	if(temp>1){
		if(bad.find(temp)!=bad.end()) ans--;
		else ans++;
	}
}
int check(int g){
	if(g==1) return 0;
	if(dp.count(g)) return dp[g];
	ll temp=g,tt=0;
	for(ll j=2;j*j<=g&&temp>1;){
		if(temp%j==0){
			temp/=j;
			if(bad.find(j)!=bad.end()) tt++;
			else tt--;
		}
		else j++;
	}
	if(temp>1){
		if(bad.find(temp)!=bad.end()) tt++;
		else tt--;
	}
	return dp[g]=tt;
}
int main()
{
    ios
    cin>>n>>k;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(!i) b[i]=a[i];
    	else b[i]=gcd(a[i],b[i-1]);
    }
    for(int i=0;i<k;i++) cin>>j,bad.insert(j);
    for(int i=0;i<n;i++) factor(i);
    ll hata_diya=1;
    for(int i=n-1;i>=0;i--){
    	ll benefit=check(b[i]/hata_diya);
    	if(benefit>=0){
    		hata_diya*=b[i]/hata_diya;
    		ans+=(i+1)*benefit;
    	}
    }
    return cout<<ans<<endl,0;
}


// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 5001;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, m, a[N];
set<int> bad;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

vector<pair<int,int> > factorize(int x) {
	vector<pair<int, int> > v;
	for(int i=2; i*i<=x; i++)
		if (x%i == 0) {
			int cnt = 0;
			while (x%i == 0) {
				x /= i;
				cnt++;
			}
			v.push_back(make_pair(i, cnt));
		}
	if (x > 1)
		v.push_back(make_pair(x, 1));
	return v;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0, b; i < m; i++) {
		scanf("%d", &b);
		bad.insert(b);
	}
	for (int i = n - 1; i >= 0; i--) {
		int g = 0;
		for (int j = 0; j <= i; j++)
			g = gcd(g, a[j]);
		vector<pair<int, int> > f = factorize(g);
		int val = 0;
		for (int j = 0; j < f.size(); j++)
			val += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
		if (val < 0) {
			for (int j = 0; j <= i; j++)
				a[j] /= g;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int> > f = factorize(a[i]);
		for (int j = 0; j < f.size(); j++)
			ans += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
	}
	printf("%d\n", ans);
	return 0;
}


// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 5001;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, m, a[N], g[N];
set<int> bad;
vector<pair<int, int> > f;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

void factorize(int x) {
	f.clear();
	for(int i=2; i*i<=x; i++)
		if (x%i == 0) {
			int cnt = 0;
			while (x%i == 0) {
				x /= i;
				cnt++;
			}
			f.push_back(make_pair(i, cnt));
		}
	if (x > 1)
		f.push_back(make_pair(x, 1));
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0, b; i < m; i++) {
		scanf("%d", &b);
		bad.insert(b);
	}
	g[0] = a[0];
	for (int i = 1; i < n; i++)
		g[i] = gcd(a[i], g[i - 1]);
	int pre = 1;
	for (int i = n - 1; i >= 0; i--) {
		g[i] /= pre;
		factorize(g[i]);
		int val = 0;
		for (int j = 0; j < f.size(); j++)
			val += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
		if (val < 0)
			pre *= g[i];
		a[i] /= pre;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		factorize(a[i]);
		for (int j = 0; j < f.size(); j++)
			ans += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
	}
	printf("%d\n", ans);
	return 0;
}


// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 5001;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, m, a[N], g[N];
set<int> bad;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

vector<pair<int,int> > factorize(int x) {
	vector<pair<int, int> > v;
	for(int i=2; i*i<=x; i++)
		if (x%i == 0) {
			int cnt = 0;
			while (x%i == 0) {
				x /= i;
				cnt++;
			}
			v.push_back(make_pair(i, cnt));
		}
	if (x > 1)
		v.push_back(make_pair(x, 1));
	return v;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0, b; i < m; i++) {
		scanf("%d", &b);
		bad.insert(b);
	}
	g[0] = a[0];
	for (int i = 1; i < n; i++)
		g[i] = gcd(a[i], g[i - 1]);
	int pre = 1;
	for (int i = n - 1; i >= 0; i--) {
		vector<pair<int, int> > f = factorize(g[i]/pre);
		int val = 0;
		for (int j = 0; j < f.size(); j++)
			val += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
		if (val < 0)
			pre *= g[i];
		a[i] /= pre;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int> > f = factorize(a[i]);
		for (int j = 0; j < f.size(); j++)
			ans += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
	}
	printf("%d\n", ans);
	return 0;
}


// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 5001;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, m, a[N];
unordered_set<int> bad;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

vector<pair<int,int> > factorize(int x) {
	vector<pair<int, int> > v;
	for(int i=2; i*i<=x; i++)
		if (x%i == 0) {
			int cnt = 0;
			while (x%i == 0) {
				x /= i;
				cnt++;
			}
			v.push_back(make_pair(i, cnt));
		}
	if (x > 1)
		v.push_back(make_pair(x, 1));
	return v;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0, b; i < m; i++) {
		scanf("%d", &b);
		bad.insert(b);
	}
	for (int i = n - 1; i >= 0; i--) {
		int g = 0;
		for (int j = 0; j <= i; j++)
			g = gcd(g, a[j]);
		vector<pair<int, int> > f = factorize(g);
		int val = 0;
		for (int j = 0; j < f.size(); j++)
			val += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
		if (val < 0) {
			for (int j = 0; j <= i; j++)
				a[j] /= g;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int> > f = factorize(a[i]);
		for (int j = 0; j < f.size(); j++)
			ans += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
	}
	printf("%d\n", ans);
	return 0;
}


// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 5001;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, m, a[N], g[N];
set<int> bad;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

vector<pair<int,int> > factorize(int x) {
	vector<pair<int, int> > v;
	for(int i=2; i*i<=x; i++)
		if (x%i == 0) {
			int cnt = 0;
			while (x%i == 0) {
				x /= i;
				cnt++;
			}
			v.push_back(make_pair(i, cnt));
		}
	if (x > 1)
		v.push_back(make_pair(x, 1));
	return v;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0, b; i < m; i++) {
		scanf("%d", &b);
		bad.insert(b);
	}
	g[0] = a[0];
	for (int i = 1; i < n; i++)
		g[i] = gcd(a[i], g[i - 1]);
	int pre = 1;
	for (int i = n - 1; i >= 0; i--) {
		g[i] /= pre;
		vector<pair<int, int> > f = factorize(g[i]);
		int val = 0;
		for (int j = 0; j < f.size(); j++)
			val += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
		if (val < 0)
			pre *= g[i];
		a[i] /= pre;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int> > f = factorize(a[i]);
		for (int j = 0; j < f.size(); j++)
			ans += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
	}
	printf("%d\n", ans);
	return 0;
}


// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 5001;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, m, a[N], g[N];
set<int> bad;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

vector<pair<int,int> > factorize(int x) {
	vector<pair<int, int> > v;
	for(int i=2; i*i<=x; i++)
		if (x%i == 0) {
			int cnt = 0;
			while (x%i == 0) {
				x /= i;
				cnt++;
			}
			v.push_back(make_pair(i, cnt));
		}
	if (x > 1)
		v.push_back(make_pair(x, 1));
	return v;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0, b; i < m; i++) {
		scanf("%d", &b);
		bad.insert(b);
	}
	g[0] = a[0];
	for (int i = 1; i < n; i++)
		g[i] = gcd(a[i], g[i - 1]);
	ll pre = 1;
	for (int i = n - 1; i >= 0; i--) {
		vector<pair<int, int> > f = factorize(g[i]/pre);
		int val = 0;
		for (int j = 0; j < f.size(); j++)
			val += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
		if (val < 0)
			pre *= g[i];
		a[i] /= pre;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int> > f = factorize(a[i]);
		for (int j = 0; j < f.size(); j++)
			ans += bad.find(f[j].first) == bad.end() ? f[j].second : -f[j].second;
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#define ll long long

using namespace std;

const int maxn = 3e5 + 10;
int n,m;
ll a[maxn] = {0};
ll gc = 0;
map <ll,int> vis;
ll prime[maxn / 10] = {0};
int cnt = 0;
void init () {
    for (int i = 2;i < maxn; ++ i) {
        if (!vis[i]) {
            prime[cnt ++] = i;
            for (int j = i + i;j < maxn; j += i) {
                vis[j] = 1;
            }
        }
    }
}

ll add = 0;
int pos = 0;
ll temp = 0;
ll g = 0;
void divide (ll n) {
    ll tem = n;
    temp = 0;
    if (n <= 1) {
        return ;
    }
    for (int i = 0;i < cnt && prime[i] * prime[i] <= n; ++ i) {
        while (tem % prime[i] == 0) {
            if (vis[prime[i]]) {
                temp --;
            }
            else temp ++;
            tem /= prime[i];
        }
    }
    if (tem != 1) {
        if (vis[tem]) {
            temp --;
        }
        else temp ++;
    }
}
int main () {
    ios_base :: sync_with_stdio(false);
    init ();
    vis.clear();
    cin >> n >> m;
    for (int i = 1;i <= n; ++ i) {
        cin >> a[i];
    }
    for (int i = 0;i < m; ++ i) {
        int x;
        cin >> x;
        vis[x] = 1;
    }
    ll ans = 0;
    for (int i = 1;i <= n; ++ i) {
        divide(a[i]);
        ans += temp;
    }
//    int flag = 0;
    for (ll i = n;i >= 1;-- i) {
        g = a[i];
        for (ll j = i;j >= 1; -- j) {
            g = __gcd (g,a[j]);
        }
        divide(g);
        cout << temp << endl;
        if (temp < 0) {
//            flag = 1;
            ans += (i * -temp);
            for (int j = 1;j <= i; ++ j) a[j] /= g;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#define ll long long

using namespace std;

const int maxn = 3e5 + 10;
int n,m;
ll a[maxn] = {0};
ll gc = 0;
map <ll,int> vis;
ll prime[maxn / 10] = {0};
int cnt = 0;
void init () {
    for (int i = 2;i < maxn; ++ i) {
        if (!vis[i]) {
            prime[cnt ++] = i;
            for (int j = i + i;j < maxn; j += i) {
                vis[j] = 1;
            }
        }
    }
}

ll add = 0;
int pos = 0;
ll temp = 0;
ll g = 0;
void divide (ll n) {
    ll tem = n;
    temp = 0;
    if (n <= 1) {
        return ;
    }
    for (int i = 0;i < cnt && prime[i] * prime[i] <= n; ++ i) {
        while (tem % prime[i] == 0) {
            if (vis[prime[i]]) {
                temp --;
            }
            else temp ++;
            tem /= prime[i];
        }
    }
    if (tem != 1) {
        if (vis[tem]) {
            temp --;
        }
        else temp ++;
    }
}
int main () {
    ios_base :: sync_with_stdio(false);
    init ();
    vis.clear();
    cin >> n >> m;
    for (int i = 1;i <= n; ++ i) {
        cin >> a[i];
    }
    for (int i = 0;i < m; ++ i) {
        int x;
        cin >> x;
        vis[x] = 1;
    }
    ll ans = 0;
    for (int i = 1;i <= n; ++ i) {
        divide(a[i]);
        ans += temp;
    }
//    int flag = 0;
    for (ll i = n;i >= 1;-- i) {
        g = a[i];
        for (ll j = i;j >= 1; -- j) {
            g = __gcd (g,a[j]);
        }
        divide(g);
//        cout << temp << endl;
        if (temp < 0) {
//            flag = 1;
            ans += (i * -temp);
            for (int j = 1;j <= i; ++ j) a[j] /= g;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#define ll long long

using namespace std;

const int maxn = 3e5 + 10;
int n,m;
ll a[maxn] = {0};
ll gc = 0;
map <ll,int> vis;
ll prime[maxn / 10] = {0};
map <ll,int> dp;
int cnt = 0;
void init () {
    for (int i = 2;i < maxn; ++ i) {
        if (!vis[i]) {
            prime[cnt ++] = i;
            for (int j = i + i;j < maxn; j += i) {
                vis[j] = 1;
            }
        }
    }
}

ll add = 0;
int pos = 0;
ll temp = 0;
ll g = 0;
void divide (ll n) {
    ll tem = n;
    temp = 0;
    if (n <= 1) {
        return ;
    }
    if (dp[n]) {
        temp = dp[n];
        return ;
    }
    for (int i = 0;i < cnt && prime[i] * prime[i] <= n; ++ i) {
        while (tem % prime[i] == 0) {
            if (vis[prime[i]]) {
                temp --;
            }
            else temp ++;
            tem /= prime[i];
        }
    }
    if (tem != 1) {
        if (vis[tem]) {
            temp --;
        }
        else temp ++;
    }
    dp[n] = temp;
}
int main () {
    ios_base :: sync_with_stdio(false);
    init ();
    vis.clear();
    cin >> n >> m;
    for (int i = 1;i <= n; ++ i) {
        cin >> a[i];
    }
    for (int i = 0;i < m; ++ i) {
        int x;
        cin >> x;
        vis[x] = 1;
    }
    ll ans = 0;
    for (int i = 1;i <= n; ++ i) {
        divide(a[i]);
        ans += temp;
    }
//    int flag = 0;
    for (ll i = n;i >= 1;-- i) {
        g = a[i];
        for (ll j = i;j >= 1; -- j) {
            g = __gcd (g,a[j]);
        }
        divide(g);
//        cout << temp << endl;
        if (temp < 0) {
//            flag = 1;
            ans += (i * -temp);
            for (int j = 1;j <= i; ++ j) a[j] /= g;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#define ll long long

using namespace std;

const int maxn = 2e5 + 10;
int n,m;
ll a[maxn] = {0};
ll gc = 0;
map <ll,int> vis;

ll prime[maxn / 10] = {0};
int cnt = 0;
void init () {
    for (int i = 2;i < maxn; ++ i) {
        if (!vis[i]) {
            prime[cnt ++] = i;
            for (int j = i + i;j < maxn; j += i) {
                vis[j] = 1;
            }
        }
    }
}

ll add = 0;
int pos = 0;
ll temp = 0;
ll g = 0;
void divide (ll n) {
    ll tem = n;
    temp = 0;
    if (n == 0) return ;
    if (n == 1) {
        temp = 1;
        return ;
    }
    for (int i = 0;i < cnt && prime[i] * prime[i] <= n; ++ i) {
        while (tem % prime[i] == 0) {
            if (vis[prime[i]]) {
                temp --;
            }
            else temp ++;
            tem /= prime[i];
        }
    }
    if (tem != 1) {
        if (vis[tem]) {
            temp --;
        }
        else temp ++;
    }
}
int main () {
    ios_base :: sync_with_stdio(false);
    init ();
    vis.clear();
    cin >> n >> m;
    for (int i = 1;i <= n; ++ i) {
        cin >> a[i];
    }
    for (int i = 0;i < m; ++ i) {
        int x;
        cin >> x;
        vis[x] = 1;
    }
    int ans = 0;
    for (int i = 1;i <= n; ++ i) {
        divide(a[i]);
        ans += temp;
    }
    for (ll i = n;i >= 1;-- i) {
        g = a[i];
        for (int j = i - 1;j >= 1; -- j) {
            g = __gcd (g,a[j]);
        }
        divide(g);
        if (temp < 0) {
            ans += (i * -temp);
            for (int j = 1;j <= i; ++ j) a[j] /= g;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#define ll long long

using namespace std;

const int maxn = 1e5 + 10;
int n,m;
ll a[maxn] = {0};
ll gc = 0;
map <ll,int> vis;
ll prime[maxn / 10] = {0};
map <ll,int> dp;
int cnt = 0;
void init () {
    for (int i = 2;i < maxn; ++ i) {
        if (!vis[i]) {
            prime[cnt ++] = i;
            for (int j = i + i;j < maxn; j += i) {
                vis[j] = 1;
            }
        }
    }
}

ll add = 0;
int pos = 0;
ll temp = 0;
ll g = 0;
void divide (ll n) {
    ll tem = n;
    temp = 0;
    if (n <= 1) {
        return ;
    }
    if (dp[n]) {
        temp = dp[n];
        return ;
    }
    for (int i = 0;i < cnt && prime[i] * prime[i] <= n; ++ i) {
        while (tem % prime[i] == 0) {
            if (vis[prime[i]]) {
                temp --;
            }
            else temp ++;
            tem /= prime[i];
        }
    }
    if (tem != 1) {
        if (vis[tem]) {
            temp --;
        }
        else temp ++;
    }
    dp[n] = temp;
}
int main () {
    ios_base :: sync_with_stdio(false);
    init ();
    vis.clear();
    cin >> n >> m;
    for (int i = 1;i <= n; ++ i) {
        cin >> a[i];
    }
    for (int i = 0;i < m; ++ i) {
        int x;
        cin >> x;
        vis[x] = 1;
    }
    ll ans = 0;
    for (int i = 1;i <= n; ++ i) {
        divide(a[i]);
        ans += temp;
    }
//    int flag = 0;
    for (ll i = n;i >= 1;-- i) {
        g = a[i];
        for (ll j = i;j >= 1; -- j) {
            g = __gcd (g,a[j]);
        }
        divide(g);
//        cout << temp << endl;
        if (temp < 0) {
//            flag = 1;
            ans += (i * -temp);
            for (int j = 1;j <= i; ++ j) a[j] /= g;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 26
#define SIZE 2
#define llp long long int
#define ld long double

using namespace std;

const llp INF=(1LL<<60)-1;
const llp MAX = 100000000001;
const llp MOD = 1000000007;

//map <int, int> prime;
int prime[10000000] = {0};

int primeFactors(int n, int decide)
{
    int cnt = 0;
    int check = 0;
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        n = n/2;
        cnt++;
    }
    if(prime[2] > 0) check += cnt;
    else check -= cnt;
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        cnt = 0;
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            n = n/i;
            cnt++;
        }
        if(prime[i] > 0) check += cnt;
        else check -= cnt;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
     {
        if(prime[n] > 0) check += 1;
        else check -= 1;
     }
    if(decide == 0)
       return check > 0 ? 1 : 0;
    return (-1) * check;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int n,m,temp_var;
    cin >> n >> m;
    int a[n+1] = {0};
    for(int i = 0; i < n; i++) cin >> a[i];
    int gcd_arr[n+1] = {0};
    gcd_arr[0] = a[0];
    for(int i = 1; i < n; i++)
     {
         gcd_arr[i] = __gcd(gcd_arr[i - 1], a[i]);
     }
    for(int i = 0; i < m; i++)
     {
        cin >> temp_var;
        prime[temp_var]++;
     }
     int fact = 1;
     int ihave[n+1] = {0};
     for(int i = n - 1; i >= 0; i--)
        {
           if( (gcd_arr[i] / fact) == 1) continue;
           int check = primeFactors( (gcd_arr[i] / fact), 0);
           if(check > 0)
            {
              ihave[i] = gcd_arr[i] / fact;
              fact *= (gcd_arr[i] / fact);
            }
        }
       int val = 1;
     for(int i = n - 1; i >= 0; i--)
        {
           if(ihave[i] > 0) val *= ihave[i];
           a[i] /= val;
        }
    int ans = 0;
    for(int i = 0; i < n; i++)
     {
        int check = primeFactors(a[i], 1);
        ans += check;
     }
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 26
#define SIZE 2
#define llp long long int
#define ld long double

using namespace std;

const llp INF=(1LL<<60)-1;
const llp MAX = 100000000001;
const llp MOD = 1000000007;

map <int, int> prime;
vector <int> l;

void SieveOfEratosthenes(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          l.pb(p);
}

int primeFactors(int n, int decide)
{
    int cnt = 0;
    int check = 0;
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        n = n/2;
        cnt++;
    }
    if(prime[2] > 0) check += cnt;
    else check -= cnt;
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 1; i <= 100000; i++)
    {
        if( l[i]*l[i] > n) break;
        cnt = 0;
        // While i divides n, print i and divide n
        while (n%l[i] == 0)
        {
            n = n/l[i];
            cnt++;
        }
        if(prime[l[i]] > 0) check += cnt;
        else check -= cnt;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
     {
        if(prime[n] > 0) check += 1;
        else check -= 1;
     }
    if(decide == 0)
       return check > 0 ? 1 : 0;
    return (-1) * check;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int n,m,temp_var;
    cin >> n >> m;
    int a[n+1] = {0};
    for(int i = 0; i < n; i++) cin >> a[i];
    int gcd_arr[n+1] = {0};
    gcd_arr[0] = a[0];
    for(int i = 1; i < n; i++)
     {
         gcd_arr[i] = __gcd(gcd_arr[i - 1], a[i]);
     }
    for(int i = 0; i < m; i++)
     {
        cin >> temp_var;
        prime[temp_var]++;
     }
     SieveOfEratosthenes(100000);
     int fact = 1;
     int ihave[n+1] = {0};
     for(int i = n - 1; i >= 0; i--)
        {
           if( (gcd_arr[i] / fact) == 1) continue;
           int check = primeFactors( (gcd_arr[i] / fact), 0);
           if(check > 0)
            {
              ihave[i] = gcd_arr[i] / fact;
              fact *= (gcd_arr[i] / fact);
            }
        }
       int val = 1;
     for(int i = n - 1; i >= 0; i--)
        {
           if(ihave[i] > 0) val *= ihave[i];
           a[i] /= val;
        }
    int ans = 0;
    for(int i = 0; i < n; i++)
     {
        int check = primeFactors(a[i], 1);
        ans += check;
     }
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 26
#define SIZE 2
#define llp long long int
#define ld long double

using namespace std;

const llp INF=(1LL<<60)-1;
const llp MAX = 100000000001;
const llp MOD = 1000000007;

map <int, int> prime;
vector <int> l;

void SieveOfEratosthenes(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          l.pb(p);
}

int primeFactors(int n, int decide)
{
    int cnt = 0;
    int check = 0;
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        n = n/2;
        cnt++;
    }
    if(prime[2] > 0) check += cnt;
    else check -= cnt;
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 1; i <= 100000; i++)
    {
        if( l[i]*l[i] > n) break;
        cnt = 0;
        // While i divides n, print i and divide n
        while (n%l[i] == 0)
        {
            n = n/l[i];
            cnt++;
        }
        if(prime[l[i]] > 0) check += cnt;
        else check -= cnt;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
     {
        if(prime[n] > 0) check += 1;
        else check -= 1;
     }
    if(decide == 0)
       return check > 0 ? 1 : 0;
    return (-1) * check;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int n,m,temp_var;
    cin >> n >> m;
    int a[n+1] = {0};
    for(int i = 0; i < n; i++) cin >> a[i];
    int gcd_arr[n+1] = {0};
    gcd_arr[0] = a[0];
    for(int i = 1; i < n; i++)
     {
         gcd_arr[i] = __gcd(gcd_arr[i - 1], a[i]);
     }
    for(int i = 0; i < m; i++)
     {
        cin >> temp_var;
        prime[temp_var]++;
     }
     SieveOfEratosthenes(100000);
     int fact = 1;
     int ihave[n+1] = {0};
     for(int i = n - 1; i >= 0; i--)
        {
           if( (gcd_arr[i] / fact) == 1) continue;
           int check = primeFactors( (gcd_arr[i] / fact), 0);
           if(check > 0)
            {
              ihave[i] = gcd_arr[i] / fact;
              fact *= (gcd_arr[i] / fact);
            }
        }
       int val = 1;
     for(int i = n - 1; i >= 0; i--)
        {
           if(ihave[i] > 0) val *= ihave[i];
           a[i] /= val;
        }
    int ans = 0;
    map <int,int> t;
    for(int i = 0; i < n; i++)
     {
        if(t[a[i]] != 0)
         {
           ans += t[a[i]];
           continue;
         }
        int check = primeFactors(a[i], 1);
        ans += check;
        t[a[i]] = check;
     }
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 26
#define SIZE 2
#define llp long long int
#define ld long double

using namespace std;

const llp INF=(1LL<<60)-1;
const llp MAX = 100000000001;
const llp MOD = 1000000007;

map <int, int> prime;

int primeFactors(int n, int decide)
{
    int cnt = 0;
    int check = 0;
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        n = n/2;
        cnt++;
    }
    if(prime[2] > 0) check += cnt;
    else check -= cnt;
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        cnt = 0;
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            n = n/i;
            cnt++;
        }
        if(prime[i] > 0) check += cnt;
        else check -= cnt;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
     {
        if(prime[n] > 0) check += 1;
        else check -= 1;
     }
    if(decide == 0)
       return check > 0 ? 1 : 0;
    return (-1) * check;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int n,m,temp_var;
    cin >> n >> m;
    int a[n+1] = {0};
    for(int i = 0; i < n; i++) cin >> a[i];
    int gcd_arr[n+1] = {0};
    gcd_arr[0] = a[0];
    for(int i = 1; i < n; i++)
     {
         gcd_arr[i] = __gcd(gcd_arr[i - 1], a[i]);
     }
    for(int i = 0; i < m; i++)
     {
        cin >> temp_var;
        prime[temp_var]++;
     }
     for(int i = n - 1; i >= 0; i--)
        {
           if(gcd_arr[i] == 1) continue;
           int check = primeFactors(gcd_arr[i], 0);
           if(check > 0)
            {
              for(int j = 0; j <= i; j++) a[j] /= gcd_arr[i];
              for(int j = 0; j <= i; j++) gcd_arr[j] /= gcd_arr[i];
            }
        }
    int ans = 0;
    for(int i = 0; i < n; i++)
     {
        int check = primeFactors(a[i], 1);
        ans += check;
     }
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 26
#define SIZE 2
#define llp long long int
#define ld long double

using namespace std;

const llp INF=(1LL<<60)-1;
const llp MAX = 100000000001;
const llp MOD = 1000000007;

map <int, int> prime;

int primeFactors(int n, int decide)
{
    int cnt = 0;
    int check = 0;
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        n = n/2;
        cnt++;
    }
    if(prime[2] > 0) check += cnt;
    else check -= cnt;
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        cnt = 0;
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            n = n/i;
            cnt++;
        }
        if(prime[i] > 0) check += cnt;
        else check -= cnt;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
     {
        if(prime[n] > 0) check += 1;
        else check -= 1;
     }
    if(decide == 0)
       return check > 0 ? 1 : 0;
    return (-1) * check;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int n,m,temp_var;
    cin >> n >> m;
    int a[n+1] = {0};
    for(int i = 0; i < n; i++) cin >> a[i];
    int gcd_arr[n+1] = {0};
    gcd_arr[0] = a[0];
    for(int i = 1; i < n; i++)
     {
         gcd_arr[i] = __gcd(gcd_arr[i - 1], a[i]);
     }
    for(int i = 0; i < m; i++)
     {
        cin >> temp_var;
        prime[temp_var]++;
     }
     int fact = 1;
     int ihave[n+1] = {0};
     for(int i = n - 1; i >= 0; i--)
        {
           if( (gcd_arr[i] / fact) == 1) continue;
           int check = primeFactors( (gcd_arr[i] / fact), 0);
           if(check > 0)
            {
              ihave[i] = gcd_arr[i] / fact;
              fact *= (gcd_arr[i] / fact);
            }
        }
       int val = 1;
     for(int i = n - 1; i >= 0; i--)
        {
           if(ihave[i] > 0) val *= ihave[i];
           a[i] /= val;
        }
    int ans = 0;
    for(int i = 0; i < n; i++)
     {
        int check = primeFactors(a[i], 1);
        ans += check;
     }
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 26
#define SIZE 2
#define llp long long int
#define ld long double

using namespace std;

const llp INF=(1LL<<60)-1;
const llp MAX = 100000000001;
const llp MOD = 1000000007;

//map <int, int> prime;
int prime[100000000] = {0};

int primeFactors(int n, int decide)
{
    int cnt = 0;
    int check = 0;
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        n = n/2;
        cnt++;
    }
    if(prime[2] > 0) check += cnt;
    else check -= cnt;
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        cnt = 0;
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            n = n/i;
            cnt++;
        }
        if(prime[i] > 0) check += cnt;
        else check -= cnt;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
     {
        if(prime[n] > 0) check += 1;
        else check -= 1;
     }
    if(decide == 0)
       return check > 0 ? 1 : 0;
    return (-1) * check;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int n,m,temp_var;
    cin >> n >> m;
    int a[n+1] = {0};
    for(int i = 0; i < n; i++) cin >> a[i];
    int gcd_arr[n+1] = {0};
    gcd_arr[0] = a[0];
    for(int i = 1; i < n; i++)
     {
         gcd_arr[i] = __gcd(gcd_arr[i - 1], a[i]);
     }
    for(int i = 0; i < m; i++)
     {
        cin >> temp_var;
        prime[temp_var]++;
     }
     int fact = 1;
     int ihave[n+1] = {0};
     for(int i = n - 1; i >= 0; i--)
        {
           if( (gcd_arr[i] / fact) == 1) continue;
           int check = primeFactors( (gcd_arr[i] / fact), 0);
           if(check > 0)
            {
              ihave[i] = gcd_arr[i] / fact;
              fact *= (gcd_arr[i] / fact);
            }
        }
       int val = 1;
     for(int i = n - 1; i >= 0; i--)
        {
           if(ihave[i] > 0) val *= ihave[i];
           a[i] /= val;
        }
    int ans = 0;
    for(int i = 0; i < n; i++)
     {
        int check = primeFactors(a[i], 1);
        ans += check;
     }
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define inf (ll)3000000000000000
#define maxn 1000010
#define MOD 1000000007
#define fre freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vector<ll> >
#define vii vector<pll>
#define vvpll vector<vector<pll> >
#define vpll vector<pll>
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) (ll)((v).size())

using namespace std;

ll lpf[maxn];
map<ll,bool> mark,vis;
map<ll,ll> dp;

void sieve()
{
	for(int i=1;i<maxn;i++)
	{
		lpf[i]=i;
	}
	for(int i=2;i<maxn;i++)
	{
		if(lpf[i]!=i) continue;
		for(int j=2*i;j<maxn;j+=i)
		{
			if(lpf[j]==j) lpf[j]=i;
		}
	}
}

ll f(ll num)
{
	if(num==1) return 0;
	if(vis[num]) return dp[num];
	vis[num]=1;
	if(mark[lpf[num]]==0) return dp[num]=f(num/lpf[num])+1;
	return dp[num]=f(num/lpf[num])-1;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	sieve();
	ll n,m;
	cin>>n>>m;
	ll a[n],b[m],cpy[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		cpy[i]=a[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
		mark[b[i]]=1;
	}
	ll ans=0,lans;
	for(int i=0;i<n;i++)
	{
		ans+=f(a[i]);
	}
	for(int i=n;i>0;--i)
	{
		ll hcf=0;
		for(int j=0;j<i;j++)
		{
			hcf=__gcd(hcf,a[j]);
		}
		for(int j=0;j<n;j++)
		{
			cpy[j]=a[j];
		}
		for(int j=0;j<i;j++)
		{
			cpy[j]/=hcf;
		}
		lans=0;
		for(int j=0;j<n;j++)
		{
			lans+=f(cpy[j]);
		}
		if(lans>ans)
		{
			ans=lans;
			for(int j=0;j<n;j++)
			{
				a[j]=cpy[j];
			}
		}
	}
	cout<<ans;
}

/*
ll gcd(ll a,ll b)
{
	while (a&&b)a>b?a%=b:b%=a;
	return a+b;
}
*/

/*
ll power(ll x,ll p,ll mod)
{
	if(p==0) return 1;
	ll ret=power(x,p/2,mod);
	ret=(ret*ret)%mod;
	if(p%2) ret=(ret*x)%mod;
	return ret;
}
*/

/*
ll modinverse(ll x,ll mod)
{
	return power(x,mod-2,mod);
}
*/


#include <bits/stdc++.h>
#define ll int
#define ld long double
#define inf (ll)3000000000000000
#define maxn 32000
#define MOD 1000000007
#define fre freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vector<ll> >
#define vii vector<pll>
#define vvpll vector<vector<pll> >
#define vpll vector<pll>
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) (ll)((v).size())

using namespace std;

ll lpf[maxn];
map<ll,bool> mark,vis;
map<ll,ll> dp;
vi primes;

void sieve()
{
	for(int i=1;i<maxn;i++)
	{
		lpf[i]=i;
	}
	for(int i=2;i<maxn;i++)
	{
		if(lpf[i]!=i) continue;
		primes.pb(i);
		for(int j=2*i;j<maxn;j+=i)
		{
			if(lpf[j]==j) lpf[j]=i;
		}
	}
}

ll f(ll num)
{
	if(num==1) return 0;
	if(vis[num]) return dp[num];
	vis[num]=1;
	ll n=num,cnt=0;
	for(int i=0;primes[i]*primes[i]<=n;i++)
	{
		while(n%primes[i]==0)
		{
			if(mark[primes[i]]==0)
			{
				cnt++;
			}else
			{
				cnt--;
			}
			n/=primes[i];
			if(num!=n&&vis[n]==1)
			{
				return dp[num]=cnt+dp[n];
			}
		}
	}
	if(n!=1)
	{
		if(mark[n]==0)
		{
			cnt++;
		}else
		{
			cnt--;
		}
	}
	return dp[num]=cnt;
}

bool check(ll hcf)
{
	return (f(hcf)<0);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	sieve();
	ll n,m;
	cin>>n>>m;
	ll a[n],b[m];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
		mark[b[i]]=1;
	}
	for(int i=n;i>0;--i)
	{
		ll hcf=0;
		for(int j=0;j<i;j++)
		{
			hcf=__gcd(hcf,a[j]);
		}
		if(check(hcf))
		{
			for(int j=0;j<i;j++)
			{
				a[j]/=hcf;
			}
		}
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=f(a[i]);
	}
	cout<<ans;
}

/*
ll gcd(ll a,ll b)
{
	while (a&&b)a>b?a%=b:b%=a;
	return a+b;
}
*/

/*
ll power(ll x,ll p,ll mod)
{
	if(p==0) return 1;
	ll ret=power(x,p/2,mod);
	ret=(ret*ret)%mod;
	if(p%2) ret=(ret*x)%mod;
	return ret;
}
*/

/*
ll modinverse(ll x,ll mod)
{
	return power(x,mod-2,mod);
}
*/


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define inf (ll)3000000000000000
#define maxn 32000
#define MOD 1000000007
#define fre freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vector<ll> >
#define vii vector<pll>
#define vvpll vector<vector<pll> >
#define vpll vector<pll>
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) (ll)((v).size())

using namespace std;

ll lpf[maxn];
map<ll,bool> mark,vis;
map<ll,ll> dp;
vi primes;

void sieve()
{
	for(int i=1;i<maxn;i++)
	{
		lpf[i]=i;
	}
	for(int i=2;i<maxn;i++)
	{
		if(lpf[i]!=i) continue;
		primes.pb(i);
		for(int j=2*i;j<maxn;j+=i)
		{
			if(lpf[j]==j) lpf[j]=i;
		}
	}
}

ll f(ll num)
{
	if(num==1) return 0;
	if(vis[num]) return dp[num];
	vis[num]=1;
	ll n=num,cnt=0;
	for(int i=0;primes[i]*primes[i]<=n;i++)
	{
		if(n%primes[i]==0)
		{
			if(mark[primes[i]]==0)
			{
				cnt++;
			}else
			{
				cnt--;
			}
			n/=primes[i];
		}
		if(num!=n&&vis[n]==1)
		{
			return dp[num]=cnt+dp[n];
		}
	}
	if(n!=1)
	{
		if(mark[n]==0)
		{
			cnt++;
		}else
		{
			cnt--;
		}
	}
	return dp[num]=cnt;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	sieve();
	ll n,m;
	cin>>n>>m;
	ll a[n],b[m],cpy[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		cpy[i]=a[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
		mark[b[i]]=1;
	}
	ll ans=0,lans;
	for(int i=0;i<n;i++)
	{
		ans+=f(a[i]);
	}
	for(int i=n;i>0;--i)
	{
		ll hcf=0;
		for(int j=0;j<i;j++)
		{
			hcf=__gcd(hcf,a[j]);
		}
		for(int j=0;j<n;j++)
		{
			cpy[j]=a[j];
		}
		for(int j=0;j<i;j++)
		{
			cpy[j]/=hcf;
		}
		lans=0;
		for(int j=0;j<n;j++)
		{
			lans+=f(cpy[j]);
		}
		if(lans>ans)
		{
			ans=lans;
			for(int j=0;j<n;j++)
			{
				a[j]=cpy[j];
			}
		}
	}
	cout<<ans;
}

/*
ll gcd(ll a,ll b)
{
	while (a&&b)a>b?a%=b:b%=a;
	return a+b;
}
*/

/*
ll power(ll x,ll p,ll mod)
{
	if(p==0) return 1;
	ll ret=power(x,p/2,mod);
	ret=(ret*ret)%mod;
	if(p%2) ret=(ret*x)%mod;
	return ret;
}
*/

/*
ll modinverse(ll x,ll mod)
{
	return power(x,mod-2,mod);
}
*/


#include <bits/stdc++.h>

using namespace std;

long long gcd(long long a, long long b)
{
    if (a < b)
        swap(a, b);

    long long tmp;
    while (b != 0)
        tmp = a % b,
        a = b,
        b = tmp;

    return a;
}

// input data
int n, m;
int input[5000];
unordered_set<int> bad_primes;

// precompute data
int prefix_gcd[5000];

int diff_between_good_and_bad_primes(int x)
{
    int good_points = 0;
    int bad_points = 0;
    int cp_x = x;

    for (int i = 2; i * i <= x; ++i)
        while (cp_x % i == 0)
        {
            if (bad_primes.find(i) == bad_primes.end())
                good_points++;
            else
                bad_points++;

            cp_x /= i;
        }

    // cp_x can be some big prime now
    if (cp_x != 1)
    {
        if (bad_primes.find(cp_x) == bad_primes.end())
            good_points++;
        else
            bad_points++;
    }

    return good_points - bad_points;
}

int main()
{
    std::ios_base::sync_with_stdio(false);

    // get input
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> input[i];
    for (int i = 0; i < m; ++i)
    {
        int tmp;
        cin >> tmp;
        bad_primes.insert(tmp);
    }

    // precompute
    prefix_gcd[0] = input[0];
    for (int i = 1; i < n; ++i)
        prefix_gcd[i] = gcd(prefix_gcd[i - 1], input[i]);

    // scan
    int accumulated_div = 1;
    for (int i = n - 1; i >= 0; --i)
    {
        int potentital_gcd = prefix_gcd[i] / accumulated_div;

        if (diff_between_good_and_bad_primes(potentital_gcd) < 0)
            accumulated_div *= potentital_gcd;

        input[i] /= accumulated_div;
    }

    // count bad primes
    int ans = 0;
    for (int i = 0; i < n; ++i)
        ans += diff_between_good_and_bad_primes(input[i]);

    cout << ans << endl;
    // cout << "input : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << input[i] << " ";
    // cout << endl;
    // cout << "prefix_gcd : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << prefix_gcd[i] << " ";
    // cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long gcd(long long a, long long b)
{
    if (a < b)
        swap(a, b);

    long long tmp;
    while (b != 0)
        tmp = a % b,
        a = b,
        b = tmp;

    return a;
}

// static data
vector<int> small_primes;

// input data
int n, m;
int input[5000];
unordered_set<int> bad_primes;

// precompute
int prefix_gcd[5000];

void init()
{
    const int stop = 100000;
    bool table[stop + 1];

    for (int i = 0; i <= stop; ++i)
        table[i] = true;

    for (int i = 2; i <= stop; ++i)
        if (table[i])
        {
            for (int j = 2; i * j <= stop; j++)
                table[i * j] = false;

            small_primes.push_back(i);
        }
}

int diff_between_good_and_bad_primes(int x)
{
    int good_points = 0;
    int bad_points = 0;

    for (int prime : small_primes)
        while (x % prime == 0)
        {
            if (bad_primes.find(prime) == bad_primes.end())
                good_points++;
            else
                bad_points++;

            x /= prime;
        }

    if (x != 1)
    {
        if (bad_primes.find(x) == bad_primes.end())
            good_points++;
        else
            bad_points++;
    }

    return good_points - bad_points;
}

int main()
{
    std::ios_base::sync_with_stdio(false);

    init();

    // get input
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> input[i];
    for (int i = 0; i < m; ++i)
    {
        int tmp;
        cin >> tmp;
        bad_primes.insert(tmp);
    }

    // precompute
    prefix_gcd[0] = input[0];
    for (int i = 1; i < n; ++i)
        prefix_gcd[i] = gcd(prefix_gcd[i - 1], input[i]);

    // scan
    int accumulated_div = 1;
    for (int i = n - 1; i >= 0; --i)
    {
        int potentital_gcd = prefix_gcd[i] / accumulated_div;

        if (diff_between_good_and_bad_primes(potentital_gcd) < 0)
            accumulated_div *= potentital_gcd;

        input[i] /= accumulated_div;
    }

    // count bad primes
    int ans = 0;
    for (int i = 0; i < n; ++i)
        ans += diff_between_good_and_bad_primes(input[i]);

    cout << ans << endl;
    // cout << "input : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << input[i] << " ";
    // cout << endl;
    // cout << "prefix_gcd : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << prefix_gcd[i] << " ";
    // cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long gcd(long long a, long long b)
{
    if (a < b)
        swap(a, b);

    long long tmp;
    while (b != 0)
        tmp = a % b,
        a = b,
        b = tmp;

    return a;
}

// input data
int n, m;
int input[5000];
unordered_set<int> bad_primes;

// precompute data
int prefix_gcd[5000];

int diff_between_good_and_bad_primes(int x)
{
    int good_points = 0;
    int bad_points = 0;
    int cp_x = x;

    for (int i = 2; i * i <= x && cp_x != 1; ++i)
        while (cp_x % i == 0)
        {
            if (bad_primes.find(i) == bad_primes.end())
                good_points++;
            else
                bad_points++;

            cp_x /= i;
        }

    // cp_x can be some big prime now
    if (cp_x != 1)
    {
        if (bad_primes.find(cp_x) == bad_primes.end())
            good_points++;
        else
            bad_points++;
    }

    return good_points - bad_points;
}

int main()
{
    std::ios_base::sync_with_stdio(false);

    // get input
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> input[i];
    for (int i = 0; i < m; ++i)
    {
        int tmp;
        cin >> tmp;
        bad_primes.insert(tmp);
    }

    // precompute
    prefix_gcd[0] = input[0];
    for (int i = 1; i < n; ++i)
        prefix_gcd[i] = gcd(prefix_gcd[i - 1], input[i]);

    // scan
    int accumulated_div = 1;
    for (int i = n - 1; i >= 0; --i)
    {
        int potentital_gcd = prefix_gcd[i] / accumulated_div;

        if (diff_between_good_and_bad_primes(potentital_gcd) < 0)
            accumulated_div *= potentital_gcd;

        input[i] /= accumulated_div;
    }

    // count bad primes
    int ans = 0;
    for (int i = 0; i < n; ++i)
        ans += diff_between_good_and_bad_primes(input[i]);

    cout << ans << endl;
    // cout << "input : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << input[i] << " ";
    // cout << endl;
    // cout << "prefix_gcd : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << prefix_gcd[i] << " ";
    // cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long gcd(long long a, long long b)
{
    if (a < b)
        swap(a, b);

    long long tmp;
    while (b != 0)
        tmp = a % b,
        a = b,
        b = tmp;

    return a;
}

// input data
int n, m;
int input[5000];
unordered_set<int> bad_primes;

// precompute data
int prefix_gcd[5000];

int diff_between_good_and_bad_primes(int x)
{
    int good_points = 0;
    int bad_points = 0;

    for (int i = 2; x > 1; ++i)
        while (x % i == 0)
        {
            if (bad_primes.find(i) == bad_primes.end())
                good_points++;
            else
                bad_points++;
            x /= i;
        }

    return good_points - bad_points;
}

int main()
{
    std::ios_base::sync_with_stdio(false);

    // get input
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> input[i];
    for (int i = 0; i < m; ++i)
    {
        int tmp;
        cin >> tmp;
        bad_primes.insert(tmp);
    }

    // precompute
    prefix_gcd[0] = input[0];
    for (int i = 1; i < n; ++i)
        prefix_gcd[i] = gcd(prefix_gcd[i - 1], input[i]);

    // scan
    int accumulated_div = 1;
    for (int i = n - 1; i >= 0; --i)
    {
        int potentital_gcd = prefix_gcd[i] / accumulated_div;

        if (diff_between_good_and_bad_primes(potentital_gcd) < 0)
            accumulated_div *= potentital_gcd;

        input[i] /= accumulated_div;
    }

    // count bad primes
    int ans = 0;
    for (int i = 0; i < n; ++i)
        ans += diff_between_good_and_bad_primes(input[i]);

    cout << ans << endl;
    // cout << "input : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << input[i] << " ";
    // cout << endl;
    // cout << "prefix_gcd : " << endl;
    // for (int i = 0; i < n; ++i)
    //     cout << prefix_gcd[i] << " ";
    // cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5008;

int num[N];
set<int> bad;
set<int> yes;
map<int, int> dat;

int n;
int m;
int p;
int a;
int d;
int tmp;
int ans;

int gcd(int a, int b)
{
    while (a && b) {
	(a > b) ? a %= b : b %= a;
    }

    return a + b;
}

int Euler(int n)
{
    int t = n;
    int c = 0;

    if (yes.find(n) != yes.end()) return dat[n];

    for (int i = 2; i * i <= n; ++i) {
	if (t % i == 0) {
	    bool check = false;
	    if (bad.find(i) != bad.end()) check = true;
	    while (t % i == 0) {
		t /= i;
		if (check) --c;
		else ++c;
	    }
	}
    }

    if (t > 1) {
	if (bad.find(t) != bad.end()) --c;
	else ++c;
    }

    yes.insert(n);
    dat[n] = c;
    return c;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; ++i) {
	scanf("%d", num + i);
    }

    for (int i = 1; i <= m; ++i) {
	scanf("%d", &p);
	bad.insert(p);
    }

    while (true) {
	a = 0;
	d = 0;
	tmp = 0;

	for (int i = 1; i <= n; ++i) {
	    tmp = gcd(tmp, num[i]);
	    if (Euler(tmp) < 0) {
		a = i;
		d = tmp;
	    }
	}

	if (a == 0) break;
	else {
	    for (int i = 1; i <= a; ++i) num[i] /= d;
	}
    }

    for (int i = 1; i <= n; ++i) {
	ans += Euler(num[i]);
    }

    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5008;

int num[N];
set<int> bad;
set<int> yes;
map<int, int> dat;

int Euler(int n)
{
    int t = n;
    int c = 0;

    if (yes.find(n) != yes.end()) return dat[n];

    for (int i = 2; i * i <= n; ++i) {
	if (t % i == 0) {
	    bool check = false;
	    if (bad.find(i) != bad.end()) check = true;
	    while (t % i == 0) {
		t /= i;
		if (check) --c;
		else ++c;
	    }
	}
    }

    if (t > 1) {
	if (bad.find(t) != bad.end()) --c;
	else ++c;
    }

    yes.insert(n);
    dat[n] = c;
    return c;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n = 0;
    int m = 0;

    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; ++i) {
	scanf("%d", num + i);
    }

    for (int i = 1; i <= m; ++i) {
	int p = 0;
	scanf("%d", &p);
	bad.insert(p);
    }

    while (true) {
	int a = 0;
	int c = 0;
	int tmp = 0;

	for (int i = 1; i <= n; ++i) {
	    tmp = __gcd(tmp, num[i]);
	    if (Euler(tmp) < 0) {
		a = i;
		c = tmp;
	    }
	}

	if (a == 0) break;
	else {
	    for (int i = 1; i <= a; ++i) num[i] /= c;
	}
    }

    int ans = 0;

    for (int i = 1; i <= n; ++i) {
	ans += Euler(num[i]);
    }

    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5008;

int num[N];
map<int, int> bad;
map<int, int> dat;

int Euler(int n)
{
    int t = n;
    int c = 0;

    if (dat.find(n) != dat.end()) return dat[n];

    for (int i = 2; i * i <= n; ++i) {
	if (t % i == 0) {
	    bool check = false;
	    if (bad.find(i) != bad.end()) check = true;
	    while (t % i == 0) {
		t /= i;
		if (check) --c;
		else ++c;
	    }
	}
    }

    if (t > 1) {
	if (bad.find(t) != bad.end()) --c;
	else ++c;
    }

    dat[n] = c;
    return c;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n = 0;
    int m = 0;

    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; ++i) {
	scanf("%d", num + i);
    }

    for (int i = 1; i <= m; ++i) {
	int p = 0;
	scanf("%d", &p);
	bad[p] = 1;
    }

    while (true) {
	int a = 0;
	int c = 0;
	int tmp = num[1];

	for (int i = 1; i <= n; ++i) {
	    tmp = __gcd(tmp, num[i]);
	    if (Euler(tmp) < 0) {
		a = i;
		c = tmp;
	    }
	}

	if (a == 0) break;
	else {
	    for (int i = 1; i <= a; ++i) num[i] /= c;
	}
    }

    int ans = 0;

    for (int i = 1; i <= n; ++i) {
	ans += Euler(num[i]);
    }

    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5008;

int num[N];
set<int> bad;
set<int> yes;
map<int, int> dat;

int Euler(int n)
{
    int t = n;
    int c = 0;

    if (yes.find(n) != yes.end()) return dat[n];

    for (int i = 2; i * i <= n; ++i) {
	if (t % i == 0) {
	    bool check = false;
	    if (bad.find(i) != bad.end()) check = true;
	    while (t % i == 0) {
		t /= i;
		if (check) --c;
		else ++c;
	    }
	}
    }

    if (t > 1) {
	if (bad.find(t) != bad.end()) --c;
	else ++c;
    }

    yes.insert(n);
    dat[n] = c;
    return c;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n = 0;
    int m = 0;

    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; ++i) {
	scanf("%d", num + i);
    }

    for (int i = 1; i <= m; ++i) {
	int p = 0;
	scanf("%d", &p);
	bad.insert(p);
    }

    while (true) {
	int a = 0;
	int c = 0;
	int tmp = num[1];

	for (int i = 1; i <= n; ++i) {
	    tmp = __gcd(tmp, num[i]);
	    if (Euler(tmp) < 0) {
		a = i;
		c = tmp;
	    }
	}

	if (a == 0) break;
	else {
	    for (int i = 1; i <= a; ++i) num[i] /= c;
	}
    }

    int ans = 0;

    for (int i = 1; i <= n; ++i) {
	ans += Euler(num[i]);
    }

    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5008;

int num[N];
set<int> bad;
set<int> yes;
map<int, int> dat;

int gcd(int a, int b)
{
    while (a && b) {
	(a > b) ? a %= b : b %= a;
    }

    return a + b;
}

int Euler(int n)
{
    int t = n;
    int c = 0;

    if (yes.find(n) != yes.end()) return dat[n];

    for (int i = 2; i * i <= n; ++i) {
	if (t % i == 0) {
	    bool check = false;
	    if (bad.find(i) != bad.end()) check = true;
	    while (t % i == 0) {
		t /= i;
		if (check) --c;
		else ++c;
	    }
	}
    }

    if (t > 1) {
	if (bad.find(t) != bad.end()) --c;
	else ++c;
    }

    yes.insert(n);
    dat[n] = c;
    return c;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n = 0;
    int m = 0;

    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; ++i) {
	scanf("%d", num + i);
    }

    for (int i = 1; i <= m; ++i) {
	int p = 0;
	scanf("%d", &p);
	bad.insert(p);
    }

    while (true) {
	int a = 0;
	int c = 0;
	int tmp = 0;

	for (int i = 1; i <= n; ++i) {
	    tmp = gcd(tmp, num[i]);
	    if (Euler(tmp) < 0) {
		a = i;
		c = tmp;
	    }
	}

	if (a == 0) break;
	else {
	    for (int i = 1; i <= a; ++i) num[i] /= c;
	}
    }

    int ans = 0;

    for (int i = 1; i <= n; ++i) {
	ans += Euler(num[i]);
    }

    printf("%d\n", ans);
    return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	seive();
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	/*for(int i=1;i<=n;i++){
		int num=A[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		if(num>1)M1[num];
		num=B[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		if(num>1)M1[num];
	}*/
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(int j=2;j*j<=A[i];j++){
			if(!prime[j])continue;
			int c=0;
			while(num%j==0)num/=j,c++;
			if(S.count(j)==0)ans+=c;
			else ans-=c;
		}
		if(num>1){
			if(S.count(num)>0)ans-=1;
			else ans+=1;
		}
	}
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		int num=B[i];
		for(int j=2;j*j<=B[i];j++){
			if(!prime[j])continue;
			int c=0;
			while(num%j==0)num/=j,c++;
			if(S.count(j)==0)p1+=c;
			else q1+=c;
		}
		if(num>1){
			if(S.count(num)==0)p1+=1;
			else q1+=1;
		}
		if(p1<q1){
			ans+=(q1-p1)*i;
			REP(j,1,n+1)B[j]/=B[i];
		}
	}
	PI(ans);
	return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
int M1[M],ptr;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
	REP(i,2,M){
		if(prime[i]&&S.count(i)==0)M1[++ptr]=i;
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	seive();
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	//TR(S.count(2));
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(int itr=1;itr<=ptr;++itr){
			if(M1[itr]>num)break;
			while(num%M1[itr]==0)num/=M1[itr];
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[++ptr]=num;
		num=B[i];
		for(int itr=1;itr<=ptr;++itr){
			if(M1[itr]>num)break;
			while(num%M1[itr]==0)num/=M1[itr];
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[++ptr]=num;
	}
	int ans=0;
	int p,q;
	p=0;
	q=0;
//	TR(M1.find(2)==M1.end());
	for(int i=1;i<=n;i++){
		//TR(A[i]);
		for(int itr=1;itr<=ptr;++itr){
			int num=0;
	//		if(itr->F==4)TR("YES");
			if(M1[itr]>A[i])break;
			while(A[i]%M1[itr]==0)A[i]/=M1[itr],num++;
			ans+=num;
		}
		//TR(A[i]);
		for(auto itr:S){
			int num=0;
			while(A[i]%itr==0)A[i]/=itr,num++;
			ans-=num;
		}
		//TR(ans);
	}
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		for(int itr=1;itr<=ptr;++itr){
			int num=0;
			if(M1[itr]>B[i])break;
			while(B[i]%M1[itr]==0)B[i]/=M1[itr],num++;
			p1+=num;
		}
		for(auto itr:S){
			int num=0;
			while(B[i]%itr==0)num++,B[i]/=itr;
			q1+=num;
		}
		p1-=p;
		q1-=q;
		if(p1<q1){
			ans+=(q1-p1)*i;
			p+=p1;
			q+=q1;
		}
	}
	PI(ans);
	return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
unordered_map<int,int> M1;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
	REP(i,2,M){
		if(prime[i]&&S.count(i)==0)M1[i];
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	seive();
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	//TR(S.count(2));
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[num];
		num=B[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[num];
	}
	int ans=0;
	int p,q;
	p=0;
	q=0;
//	TR(M1.find(2)==M1.end());
	for(int i=1;i<=n;i++){
		//TR(A[i]);
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			int num=0;
	//		if(itr->F==4)TR("YES");
			while(A[i]%itr->F==0)A[i]/=itr->F,num++;
			ans+=num;
		}
		//TR(A[i]);
		for(auto itr:S){
			int num=0;
			while(A[i]%itr==0)A[i]/=itr,num++;
			ans-=num;
		}
		//TR(ans);
	}
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			int num=0;
			while(B[i]%itr->F==0)B[i]/=itr->F,num++;
			p1+=num;
		}
		for(auto itr:S){
			int num=0;
			while(B[i]%itr==0)num++,B[i]/=itr;
			q1+=num;
		}
		p1-=p;
		q1-=q;
		if(p1<q1){
			ans+=(q1-p1)*i;
			p+=p1;
			q+=q1;
		}
	}
	PI(ans);
	return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
int M1[M],ptr;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
	REP(i,2,M){
		if(prime[i]&&S.count(i)==0)M1[++ptr]=i;
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	seive();
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	//TR(S.count(2));
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(int itr=1;itr<=ptr;++itr){
			if(M1[itr]>num)break;
			while(num%M1[itr]==0)num/=M1[itr];
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[++ptr]=num;
		num=B[i];
		for(int itr=1;itr<=ptr;++itr){
			if(M1[itr]>num)break;
			while(num%M1[itr]==0)num/=M1[itr];
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[++ptr]=num;
	}
	int ans=0;
	int p,q;
	p=0;
	q=0;
//	TR(M1.find(2)==M1.end());
	for(int i=1;i<=n;i++){
		//TR(A[i]);
		for(int itr=1;itr<=ptr;++itr){
			int num=0;
	//		if(itr->F==4)TR("YES");
			if(M1[itr]>A[i])break;
			while(A[i]%M1[itr]==0)A[i]/=M1[itr],num++;
			ans+=num;
		}
		//TR(A[i]);
		for(auto itr:S){
			int num=0;
			while(A[i]%itr==0)A[i]/=itr,num++;
			ans-=num;
		}
		//TR(ans);
	}
	//TR(ans);
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		int ty=B[i];
		for(int itr=1;itr<=ptr;++itr){
			int num=0;
			if(M1[itr]>B[i])break;
			while(B[i]%M1[itr]==0)B[i]/=M1[itr],num++;
			p1+=num;
		}
		for(auto itr:S){
			int num=0;
			while(B[i]%itr==0)num++,B[i]/=itr;
			q1+=num;
		}
		if(p1<q1){
			ans+=(q1-p1)*i;
			REP(j,1,n+1){
				B[j]/=ty;
			}
		}
	}
	PI(ans);
	return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	seive();
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(int j=2;j*j<=A[i];j++){
			if(!prime[j])continue;
			int c=0;
			while(num%j==0)num/=j,c++;
			if(S.count(j)==0)ans+=c;
			else ans-=c;
		}
		if(num>1){
			if(S.count(num)>0)ans-=1;
			else ans+=1;
		}
	}
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		int num=B[i];
		for(int j=2;j*j<=B[i];j++){
			if(!prime[j])continue;
			int c=0;
			while(num%j==0)num/=j,c++;
			if(S.count(j)==0)p1+=c;
			else q1+=c;
		}
		if(num>1){
			if(S.count(num)==0)p1+=1;
			else q1+=1;
		}
		if(p1<q1){
			ans+=(q1-p1)*i;
			REP(j,1,n+1)B[j]/=B[i];
		}
	}
	PI(ans);
	return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
map<int,int> M1;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
	REP(i,2,M){
		if(prime[i])M1[i];
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	seive();
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		if(num>1)M1[num];
		num=B[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		if(num>1)M1[num];
	}
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	int ans=0;
	int p,q;
	p=0;
	q=0;
	for(int i=1;i<=n;i++){
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			int num=0;
			while(A[i]%itr->F==0)A[i]/=itr->F,num++;
			if(S.count(itr->F)>0)ans-=num;
			else ans+=num;
		}
	}
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			int num=0;
			while(B[i]%itr->F==0)B[i]/=itr->F,num++;
			if(S.count(itr->F)>0)q1+=num;
			else p1+=num;
		}
		p1-=p;
		q1-=q;
		if(p1<q1){
			ans+=(q1-p1)*i;
			p+=p1;
			q+=q1;
		}
	}
	PI(ans);
	return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
int M1[M],ptr;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
	REP(i,2,M){
		if(prime[i]&&S.count(i)==0)M1[++ptr]=i;
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	seive();
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	//TR(S.count(2));
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(int itr=1;itr<=ptr;++itr){
			while(num%M1[itr]==0)num/=M1[itr];
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[++ptr]=num;
		num=B[i];
		for(int itr=1;itr<=ptr;++itr){
			while(num%M1[itr]==0)num/=M1[itr];
		}
		for(auto itr:S){
			while(num%itr==0)num/=itr;
		}
		if(num>1&&S.count(num)==0)M1[++ptr]=num;
	}
	int ans=0;
	int p,q;
	p=0;
	q=0;
//	TR(M1.find(2)==M1.end());
	for(int i=1;i<=n;i++){
		//TR(A[i]);
		for(int itr=1;itr<=ptr;++itr){
			int num=0;
	//		if(itr->F==4)TR("YES");
			while(A[i]%M1[itr]==0)A[i]/=M1[itr],num++;
			ans+=num;
		}
		//TR(A[i]);
		for(auto itr:S){
			int num=0;
			while(A[i]%itr==0)A[i]/=itr,num++;
			ans-=num;
		}
		//TR(ans);
	}
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		for(int itr=1;itr<=ptr;++itr){
			int num=0;
			while(B[i]%M1[itr]==0)B[i]/=M1[itr],num++;
			p1+=num;
		}
		for(auto itr:S){
			int num=0;
			while(B[i]%itr==0)num++,B[i]/=itr;
			q1+=num;
		}
		p1-=p;
		q1-=q;
		if(p1<q1){
			ans+=(q1-p1)*i;
			p+=p1;
			q+=q1;
		}
	}
	PI(ans);
	return 0;
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int M=1e5+1;
const int N=5e3+5;
int A[N];
int B[N];
set<int> S;
unordered_map<int,int> M1;
bool prime[M];

void seive()
{
	REP(i,2,M)prime[i]=true;
	for(int i=2;i*i<M;i++){
		if(prime[i]){
			for(int j=2*i;j<M;j+=i){
				prime[j]=false;
			}
		}
	}
	REP(i,2,M){
		if(prime[i])M1[i];
	}
}

int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	seive();
	int n,m;SI(n);SI(m);
	REP(i,1,n+1){
		SI(A[i]);
	}
	int gd=A[1];
	REP(i,1,n+1){
		gd=__gcd(gd,A[i]);
		B[i]=gd;
	}
	for(int i=1;i<=n;i++){
		int num=A[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		if(num>1)M1[num];
		num=B[i];
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			while(num%itr->F==0)num/=itr->F;
		}
		if(num>1)M1[num];
	}
	REP(i,1,m+1){
		int a ;SI(a);
		S.insert(a);
	}
	int ans=0;
	int p,q;
	p=0;
	q=0;
	for(int i=1;i<=n;i++){
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			int num=0;
			while(A[i]%itr->F==0)A[i]/=itr->F,num++;
			if(S.count(itr->F)>0)ans-=num;
			else ans+=num;
		}
	}
	for(int i=n;i>=1;i--){
		int p1,q1;
		p1=q1=0;
		for(auto itr=M1.begin();itr!=M1.end();++itr){
			int num=0;
			while(B[i]%itr->F==0)B[i]/=itr->F,num++;
			if(S.count(itr->F)>0)q1+=num;
			else p1+=num;
		}
		p1-=p;
		q1-=q;
		if(p1<q1){
			ans+=(q1-p1)*i;
			p+=p1;
			q+=q1;
		}
	}
	PI(ans);
	return 0;
}