I am completing a problem in hackerrank that counts the number of integers that can be divided by all elements of a set $A$ and divide all elements of another set $B$.
I completed the problem using a ugly brute force method then found the following solution.
- Find the LCM of $A$
- Find the GCD of $B$
- Find how many divisors $GCD(B)/LCM(A)$ has.
From going through a few examples I can see that it works. I am not sure WHY though.