human
Absolute difference between the XOR of Non | Function to find the absolute difference between the XOR of non - primes and the XOR of primes in the given array.
Find maximum value in the array.
USE SIEVE TO FIND ALL PRIME NUMBERS LESS THAN OR EQUAL TO max_val Create a boolean array " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true ..
Remaining part of SIEVE.
If prime [ p ] is not changed , then it is a prime.
Update all multiples of p.
Store the XOR of primes in X1 and the XOR of non primes in X2.
The number is prime.
The number is non - prime.
Return the absolute difference.
Driver code.
Find the absolute difference"
How can the above be solved in Python?
 What is a code to absolute difference between the XOR of Non and the other steps required?
assistant
#Here is code to absolute difference between the XOR of Non and the other steps required.
 def calculateDifference ( arr , n ) :
	max_val = max ( arr )
	prime = [ True for i in range ( max_val + 1 ) ]
	prime [ 0 ] = False
	prime [ 1 ] = False
	for p in range ( 2 , max_val + 1 ) :
		if p * p > max_val + 1 :
			break
		if ( prime [ p ] == True ) :
			for i in range ( 2 * p , max_val + 1 , p ) :
				prime [ i ] = False
	X1 = 1
	X2 = 1
	for i in range ( n ) :
		if ( prime [ arr [ i ] ] ) :
			X1 ^= arr [ i ]
		elif ( arr [ i ] != 1 ) :
			X2 ^= arr [ i ]
	return abs ( X1 - X2 )
arr = [ 1 , 3 , 5 , 10 , 15 , 7 ]
n = len ( arr )
print ( calculateDifference ( arr , n ) )