#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <climits>
#include <sstream>
#include <functional>
#include <complex>

using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define Rep(i, e) for(int i = 0;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define Rrep(i, e) for(int i = e;0 <= i;i--)
#define mrep(i, e, t1, t2) for(map<t1, t2>::iterator i = e.begin(); i != e.end(); i++)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
#define pb push_back
#define rg(e, s, t) s <= e && e < t
#define PQDecl(name, tp) priority_queue< tp, vector<tp>, greater<tp> > name;
//#define X real()
//#define Y imag()
//typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef complex<double> p;
const int INF = (int)2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const ll weight[] = {1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13};
#define MAX_N 1000

#define MAX_PRIMES 10000002
bool bPrimes[MAX_PRIMES];
vector<int> primes;

void makePrimes(){
  afill(bPrimes, true);
  bPrimes[0] = bPrimes[1] = false;
  rep(i, 2, MAX_PRIMES){
	if(bPrimes[i]){
	  primes.push_back(i);
	  for(int j = 2*i; j < MAX_PRIMES; j += i) bPrimes[j] = false;
	}
  }
}

ll gcd(ll a, ll b) {
  if( a < b ) swap( a, b );
  return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll lpow(ll n, ll p){
  ll ans = 1, ln = n;
  if(p <= 0) return 1;
  while(p != 0){
	if((p & 1) == 1) ans = ans*ln;
	ln = ln * ln;
	p = p >> 1;
  }
  return ans;
}

void doIt(){
  makePrimes();
  // cout << primes.size() << endl;
  int n, m, p[700000], ptmp[700000];
  ll a, b, g = -1;
  map<ll, int> mmap;
  cin >> n >> m;
  Rep(i, n){
    cin >> a;
    if(g == -1) g = a;
    else g = gcd(g, a);
  }

  afill(p, 0);
  Rep(i, m){
    cin >> b;
    afill(ptmp, 0);
    Rep(j, primes.size()){
      while(b % primes[j] == 0){
        b /= primes[j];
        ptmp[j]++;
      }
      p[j] = max(p[j], ptmp[j]);
    }
    if(b != 1) mmap[b]++;
  }
  bool bOK = true;
  ll ans = 1;
  Rep(i, primes.size()){
    int count = 0;
    while(g % primes[i] == 0){
      g /= primes[i];
      count++;
    }
    int diff = count - p[i];
    if(diff >= 0) ans *= diff + 1;
    else bOK = false;
    // if(diff) printf("diff = %d, i = %d\n", diff, i);
  }
  if(g != 1){
    if(mmap.count(g) != 0){
      mmap[g] = 0;
    }
    else{
      ans *= 2;
    }
  }
  mrep(it, mmap, ll, int){
    if((*it).second){
      bOK = false;
    }
  }
  // printf("bOK = %d\n", bOK);
  if(bOK){
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
}

int main() {
  doIt();
  return 0;
}


Measured memory_bytes: 20464