Print all possible pair with prime XOR in the Array | Javascript implementation of the above approach ; Function for Sieve of Eratosthenes ; If i is prime , then make all multiples of i false ; Function to print all Pairs whose XOR is prime ; if A [ i ] ^ A [ j ] is prime , then print this pair ; Driver Code ; Generate all the prime number ; Function Call
const sz = 100000 ; let isPrime = new Array ( sz + 1 ) . fill ( true ) ; function generatePrime ( ) { let i , j ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } function Pair_of_PrimeXor ( A , n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( isPrime [ ( A [ i ] ^ A [ j ] ) ] ) { document . write ( " " + A [ i ] + " " + A [ j ] + " " ) ; } } } } let A = [ 1 , 3 , 6 , 11 ] ; let n = A . length ; generatePrime ( ) ; Pair_of_PrimeXor ( A , n ) ;