Given an array A [ ] and a number x , check for pair in A [ ] with sum as x | Function to print pairs ; Initializing the rem values with 0 's. ; Perform the remainder operation only if the element is x , as numbers greater than x can 't  be used to get a sum x.Updating  the count of remainders. ; Traversing the remainder list from start to middle to find pairs ; The elements with remainders i and x - i will result to a sum of x . Once we get two elements which add up to x , we print x and break . ; Once we reach middle of remainder array , we have to do operations based on x . ; If x is even and we have more than 1 elements with remainder x / 2 , then we will have two distinct elements which add up to x . if we dont have than 1 element , print " No " . ; When x is odd we continue the same process which we did in previous loop . ; Driver Code ; Function calling
def printPairs ( a , n , x ) : NEW_LINE INDENT rem = [ ] NEW_LINE for i in range ( x ) : NEW_LINE INDENT rem . append ( 0 ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] < x ) : NEW_LINE INDENT rem [ a [ i ] % x ] += 1 NEW_LINE DEDENT DEDENT for i in range ( 1 , x // 2 ) : NEW_LINE INDENT if ( rem [ i ] > 0 and rem [ x - i ] > 0 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE break NEW_LINE DEDENT DEDENT if ( i >= x // 2 ) : NEW_LINE INDENT if ( x % 2 == 0 ) : NEW_LINE INDENT if ( rem [ x // 2 ] > 1 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( rem [ x // 2 ] > 0 and rem [ x - x // 2 ] > 0 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT A = [ 1 , 4 , 45 , 6 , 10 , 8 ] NEW_LINE n = 16 NEW_LINE arr_size = len ( A ) NEW_LINE printPairs ( A , arr_size , n ) NEW_LINE