object Main extends App {
  import scala.io.StdIn._


  val prime = primes
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val a = readLine.trim.split(' ').map(_.toLong)
  val b = readLine.trim.split(' ').map(_.toLong)
  val g = a.reduce(gcd)
  if (b.forall(g % _ == 0)) {
    val l = primeFactors(b.map(g / _).reduce(gcd), prime)
    println(l.map(_ + 1).product)
  }else {
    println(0)
  }
  def primes: Array[Int] = {
    val upper = 10000000
    val memo = Array.tabulate(upper / 2 + 1){_ ⇒ true}
    memo(0) = false
    for (i ← 3 to math.sqrt(upper).toInt by 2){//(i * 2 + 1) * (i * 2 + 1) < upperである間は行う必要がある。少し超えてる
      if (memo(i / 2)){//i*2+1が素数
        for (j ← 3 to upper / i by 2) {
          memo((j * i) / 2) = false
        }
      }
    }
    (2 +: memo.indices.filter(memo).map(_ * 2 + 1)).toArray
  }
  def primeFactors(target: Long, prime: Array[Int]): List[Int] = {
    var i = 0
    var rest = target
    var result = Nil: List[Int]
    while (rest > 1 && prime.indices.contains(i)){
      if (rest % prime(i) == 0) result ::= 0
      while(rest % prime(i) == 0){
        result = result.head + 1 :: result.tail
        rest /= prime(i)
      }
      i += 1
    }
    if (rest != 1) 1::result
    else result
  }
  def gcd(a: Long, b: Long): Long = {
    if (b == 0) a else gcd(b, a % b)
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
