You are viewing a single comment's thread. Return to all comments →
void calculate_the_maximum(int n, int k) { int and=0, or=0, xor=0, and_max=0,or_max=0, xor_max=0; for(int i=1;i<n;i++){ for(int j=i+1;j<=n; j++){ if((i&j)<k){ and = i&j; if(and >and_max){ and_max=and; } } if((i|j)<k){ or = i|j; if(or>or_max){ or_max=or; } } if((i^j)<k){ xor = i^j; if(xor>xor_max){ xor_max=xor; } } } } printf("%d\n",and_max); printf("%d\n",or_max); printf("%d\n",xor_max); } int main() { int n, k; scanf("%d %d", &n, &k); calculate_the_maximum(n, k); return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Bitwise Operators
You are viewing a single comment's thread. Return to all comments →