can anyone explain tell me the approach to solve this ques?

pls explain with the help of an example

I guess, this is pretty easy. You have been asked to find the number of pairs (A[i],A[j]) whence min(A[i],A[j]).

All that you’ll need is basic mathematical intuition. Let us take an arbitrary pair of numbers a,b. Now, If a and b are relatively prime, their LCM is certainly greater than both of them, so it’s not something we are looking for. Same is the case when a and b share a common factor. When one of a and b divide the other, their LCM is equal to max(a,b). So, none of these are what we are looking for !

So when indeed is LCM(a,b) = min(a,b) ??? Only when a=b. ( of course ).

So all you need to do is subtract the number of pairs (a,b) such that a=b , from the total number of pairs that can be formed with the elements of the array.

This part is fairly easy as well. First you find out the total number of pairs you can possibly form with the given array elements = ( N C 2 ) Then, you find out the number of identical elements in the list, call it K. Then the number of pairs you can form with these = ( K C 2 )

Your answer is most certainly = ( N C 2 ) - ( K C 2 )

{ And since you’ve asked for an example, take the array given in the testcase 1 1 2 3 . N is 4 here. So
( N C 2 )= 6. K = 2 here ( 1 is the only identical element that occurs twice ). So, ( K C 2 ) = 1.
So, your required answer : 6 - 1 = 5. }

I hope that helps.

thanx @swarnbja19

Welcome :slight_smile: