Print all possible pair with prime XOR in the Array | Python implementation of the above approach ; Function for Sieve of Eratosthenes ; If i is prime , then make all multiples of i false ; Function to prall Pairs whose XOR is prime ; if A [ i ] ^ A [ j ] is prime , then prthis pair ; Driver Code ; Generate all the prime number ; Function Call
sz = 10 ** 5 NEW_LINE isPrime = [ True ] * ( sz + 1 ) NEW_LINE def generatePrime ( ) : NEW_LINE INDENT i , j = 0 , 0 NEW_LINE isPrime [ 0 ] = isPrime [ 1 ] = False NEW_LINE for i in range ( 2 , sz + 1 ) : NEW_LINE INDENT if i * i > sz : NEW_LINE INDENT break NEW_LINE DEDENT if ( isPrime [ i ] ) : NEW_LINE INDENT for j in range ( i * i , sz , i ) : NEW_LINE INDENT isPrime [ j ] = False NEW_LINE DEDENT DEDENT DEDENT DEDENT def Pair_of_PrimeXor ( A , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( isPrime [ ( A [ i ] ^ A [ j ] ) ] ) : NEW_LINE INDENT print ( " ( " , A [ i ] , " , " , A [ j ] , " ) " , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 1 , 3 , 6 , 11 ] NEW_LINE n = len ( A ) NEW_LINE generatePrime ( ) NEW_LINE Pair_of_PrimeXor ( A , n ) NEW_LINE DEDENT