• + 0 comments

    Passed all Testcases

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    //Complete the following function.
    void calculate_the_maximum(int n, int k) {
        //Write your code here.
        int and, or, xor, i, j;
        int sla=0, slo=0, slx=0;
        for(i = 1; i<n; i++){
            for(j = i+1; j<=n; j++){
                and = i&j;
                or = i|j;
                xor = i^j;
                
                // assume largest is k and find second largest for and operation 
                if(and<k && and>sla){
                    sla = and;
                }
                
                // assume largest is k and find second largest for or operation
                if(or<k && or>slo){
                    slo = or;
                }
                
                // assume largest is k and find second largest for xor operation
                if(xor<k && xor>slx){
                    slx = xor;
                }
                
            }
        }
       
      printf("%d\n", sla);
      printf("%d\n", slo);
      printf("%d\n", slx);
      
    }
    
    int main() {
        int n, k;
      
        scanf("%d %d", &n, &k);
        calculate_the_maximum(n, k);
     
        return 0;
    }