Count pairs of points having distance between them equal to integral values in a K | Function to find pairs whose distance between the points of is an integer value . ; Stores count of pairs whose distance between points is an integer ; Traverse the array , points [ ] ; Stores distance between points ( i , j ) ; Traverse all the points of current pair ; Update temp ; Update dist ; If dist is a perfect square ; Update ans ; Given value of K ; Given points ; Given value of N ; Function Call
def cntPairs ( points , n , K ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT dist = 0 NEW_LINE for k in range ( K ) : NEW_LINE INDENT temp = ( points [ i ] [ k ] - points [ j ] [ k ] ) NEW_LINE dist += temp * temp NEW_LINE DEDENT if ( ( ( dist ) ** ( 1 / 2 ) ) * ( ( dist ) ** ( 1 / 2 ) ) == dist ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT K = 2 NEW_LINE points = [ [ 1 , 2 ] , [ 5 , 5 ] , [ - 2 , 8 ] ] NEW_LINE n = len ( points ) NEW_LINE cntPairs ( points , n , K ) NEW_LINE