You are viewing a single comment's thread. Return to all comments →
def getTotalX(a, b):
return len([1 for i in range(max(a),min(b)+1) if all([i%j==0 for j in a]) and all([j%i==0 for j in b])])
can u explain it.
for the question you must first understand that
1. The elements of the first array are all factors of the integer being considered:
-this means that the integers that should be taken in account will be equal to or bigger than the maximum element in the first array.
2. The integer being considered is a factor of all elements of the second array:
-this means that the integers that should be taken in account will be equal to or lesser than the minimum element of the second array
in this way we get thefirst number to be checked, then we use a loop to check if the conditions are satisfied using modulo operator and and we get the solution
hope this clears your doubt
Can you please explain it.
Thank you !!