human
Can you provide a code to all pairs whose xor gives unique prime and the other steps required given the following:
All pairs whose xor gives unique prime | Function that returns true if n is prime.
Corner cases.
This is checked so that we can skip middle five numbers in below loop.
Function to return the count of valid pairs.
If xor ( a [ i ] , a [ j ] ) is prime and unique.
Driver code"
Solution in Python:
assistant
#Here is code to all pairs whose xor gives unique prime and the other steps required.
 def isPrime ( n ) :
	if n <= 1 :
		return False
	if n <= 3 :
		return True
	if n % 2 == 0 or n % 3 == 0 :
		return False
	i = 5
	while i * i <= n :
		if n % i == 0 or n % ( i + 2 ) == 0 :
			return False
		i += 6
	return True
def countPairs ( a , n ) :
	count = 0
	m = dict ( )
	for i in range ( n - 1 ) :
		for j in range ( i + 1 , n ) :
			if isPrime ( a [ i ] ^ a [ j ] ) and m . get ( a [ i ] ^ a [ j ] , 0 ) == 0 :
				m [ ( a [ i ] ^ a [ j ] ) ] = 1
				count += 1
	return count
a = [ 10 , 12 , 23 , 45 , 5 , 6 ]
n = len ( a )
print ( countPairs ( a , n ) )