Generate an array of minimum sum whose XOR of same | C ++ implementation of the above approach ; Function to generate an array whose XOR with same - indexed elements of the given array is always a prime ; Traverse the array ; If current array element is 2 ; Print its XOR with 3 ; Otherwise ; Print its XOR with 2 ; Driver Code ; Given array ; Size of the array ; Prints the required array
#include <bits/stdc++.h> NEW_LINE using namespace std ; void minXOR ( vector < int > & Arr , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( Arr [ i ] == 2 ) { cout << ( Arr [ i ] ^ 3 ) << " ▁ " ; } else { cout << ( Arr [ i ] ^ 2 ) << " ▁ " ; } } } int main ( ) { vector < int > Arr = { 5 , 4 , 7 , 6 } ; int N = Arr . size ( ) ; minXOR ( Arr , N ) ; return 0 ; }