Count of pairs in range [ P , Q ] with numbers as multiple of R and their product lie in range [ P * Q / 4 , P * Q ] | Function to find the number of pairs such that both the elements are in the range [ P , Q ] and the numbers should be multiple of R , and the product of numbers should lie in the range [ P * Q / 4 , P * Q ] ; Store multiple of r in range of [ P , Q ] ; Itearte in the range [ p , q ] ; Vector to store pair of answer ; Iterate through the vector v ; Iterate in the range [ i + 1 , v . size ( ) - 1 ] ; If pair follow this condition insert the pair in vector ans ; If no pair satisfy the conditions , pr - 1 ; Print the pairs which satisfy the given condition ; Driver Code ; Given Input ; Function Call
def findPairs ( p , q , r ) : NEW_LINE INDENT v = [ ] NEW_LINE for i in range ( p , q + 1 ) : NEW_LINE INDENT if ( i % r == 0 ) : NEW_LINE INDENT v . append ( i ) NEW_LINE DEDENT DEDENT ans = [ ] NEW_LINE for i in range ( len ( v ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( v ) ) : NEW_LINE INDENT if ( v [ i ] * v [ j ] >= p * q // 4 and v [ i ] * v [ j ] <= p * q ) : NEW_LINE INDENT ans . append ( [ v [ i ] , v [ j ] ] ) NEW_LINE DEDENT DEDENT DEDENT if ( len ( ans ) == 0 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( len ( ans ) ) : NEW_LINE INDENT print ( ans [ i ] [ 0 ] , ans [ i ] [ 1 ] ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT p = 14 NEW_LINE q = 30 NEW_LINE r = 5 NEW_LINE findPairs ( p , q , r ) NEW_LINE DEDENT