Numbers Between Multiples and Divisors
Time limit2sMemory limit128 MB
Find how many positive integers are simultaneously a common multiple of array D and a common divisor of array M by combining LCM and GCD with divisor counting.
- Level
Medium4 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
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
Ddividesx; in other words,xis a common multiple of all elements inD. xdivides every element ofM; in other words,xis a common divisor of all elements inM.
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.