Problem: 2057C - Trip to the Olympiad
Language: java

Solution 1 (runtime: 374 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int t = sc.nextInt();
        while(t-- != 0){
            int l = sc.nextInt(), r = sc.nextInt();
            int a = 0, b = 0, c = 0;
            int n1 = countBits(l), n2 = countBits(r);
            if(r - l == 2){
                a = l; b = a + 1; c = b + 1;
            }
            else{
                int count = 0;
                for(int i = Math.max(n1, n2) - 1; i >= 0; i--){
                    int bit1 = ((l & (int)(1 << i)) == 0) ? 0 : 1;
                    int bit2 = ((r & (int)(1 << i)) == 0) ? 0 : 1;
                    count = i;
                    if(bit1 != bit2){
                        break;
                    }
                    int val = bit1 << i;
                    a += val; b += val;
                }
                a += (int)(1 << count);
                for(int i = count - 1; i >= 0; i--){
                    b += (int)(1 << i);
                }
                for(int i = l; i <= r; i++){
                    if(a != i && b != i){
                        c = i;
                        break;
                    }
                }
            }
            out.println(a + " " + b + " " + c);
        }
        out.close();
        }
    
    static int countBits(int n){
        int count = 0;
        while(n != 0){
            n /= 2;
            count++;
        }
        return count;
    }

        static class FastScanner {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer st = new StringTokenizer("");
     
            String next() {
                while (!st.hasMoreTokens())
                    try {
                        st = new StringTokenizer(br.readLine());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                return st.nextToken();
            }
     
            int nextInt() {
                return Integer.parseInt(next());
            }
     
            int[] readArray(int n) {
                int[] a = new int[n];
                for (int i = 0; i < n; i++)
                    a[i] = nextInt();
                return a;
            }
     
            long nextLong() {
                return Long.parseLong(next());
            }
        }

    }

Solution 2 (runtime: 249 ms):
import java.util.*;
public class triptotheolympiad {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int testCase = 0; testCase < t; testCase++){
            long l = sc.nextLong();
            long r = sc.nextLong();

            String lBinary = Long.toBinaryString(l);
            String rBinary = Long.toBinaryString(r);

            int bit = -1;
            if(lBinary.length() < rBinary.length()){
                bit = rBinary.length() - 1;
            }else{
                //System.out.println(lBinary + " " + rBinary);
                for(int i = 0; i < rBinary.length(); i++){
                    if(lBinary.charAt(i) == rBinary.charAt(i)){
                        continue;
                    }else{
                        bit = rBinary.length() - i - 1;
                        break;
                    }
                }
            }

            long val = (long) Math.pow(2, bit);
            long firstNumber = (r / val) * val;

            long secondNumber = firstNumber - 1;
            long thirdNumber = 0;
            if(firstNumber == r){
                thirdNumber = r - 2;
            }else{
                thirdNumber = r;
            }

            System.out.println(firstNumber + " " + secondNumber + " " + thirdNumber);
        }

    }
}