We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Java solution. Iterate through the numbers between max in A and min in B, sum up the modulus (since for something to be a factor modulus has to equal zero), and count the number of numbers that are between the two sets.

Note this is sorting a and b (which takes O(n log n)) solely for the sake of getting the max and min in contant time. This can be improved by linearly searching for the max/min in O(n)

## Between Two Sets

You are viewing a single comment's thread. Return to all comments →

Java solution. Iterate through the numbers between max in A and min in B, sum up the modulus (since for something to be a factor modulus has to equal zero), and count the number of numbers that are between the two sets.

lower_bound=a[0];

upper_bound=b[m-1]; More or less the same but this also works.

Note this is sorting a and b (which takes O(n log n)) solely for the sake of getting the max and min in contant time. This can be improved by linearly searching for the max/min in O(n)