cho.sh
Notes
Loading...

Numbers Between Multiples and Divisors

Time limit

2s

Memory limit

128 MB

Problem

You are given two arrays of positive integers, D and M. Count the number of positive integers x that satisfy both conditions below.

  • Every element of D divides x; in other words, x is a common multiple of all elements in D.
  • x divides every element of M; in other words, x is a common divisor of all elements in M.

Input

The first line contains the sizes N and K of arrays D and M. The second line contains N elements of D. The third line contains K elements of M.

Both N and K are at most 50, and every element is a positive integer not greater than 10^9.

Output

Print the number of positive integers that satisfy the conditions.