You are given a number A.
You have to find 2 numbers B and C such that A xor B is minimum and A xor C is maximum.
Example:
Input: a = 7
Output: 7 0
Approach
C++
#include <bits/stdc++.h>using namespace std;void tryFirst(int a){int b = a;int c = a;int n = log2(a) + 1;for (int i = 0; i < n; i++){c = c ^ (1 << i);}cout << b << " " << c << "\n";}int main(){int a = 7;tryFirst(a);return 0;}
No comments:
Post a Comment