• + 0 comments

    class Result {

    /*
     * Complete the 'bitwiseAnd' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts following parameters:
     *  1. INTEGER N
     *  2. INTEGER K
     */
    
    public static int bitwiseAnd(int n, int k) {
    // Write your code here
    

    int max = 0; for (int i = 1; i <= n; i++) { if (i == k-1) continue; int val = i&(k-1); if (val > max && val < k) max = val; } return max; }

    }

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        int t = Integer.parseInt(bufferedReader.readLine().trim());
    
        for (int tItr = 0; tItr < t; tItr++) {
            String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
            int count = Integer.parseInt(firstMultipleInput[0]);
    
            int lim = Integer.parseInt(firstMultipleInput[1]);
    
            int res = Result.bitwiseAnd(count, lim);
    
            bufferedWriter.write(String.valueOf(res));
            bufferedWriter.newLine();
        }
    
        bufferedReader.close();
        bufferedWriter.close();
    }
    

    }