Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int log_base_2(int n){
    if(n<=0)return -1;
    int ans = 0;
    while(n != 1){
        n /= 2;
        ans++;
    }
    return ans;
}

int pow_2(int n){
    if(n<=0)return -1;
    int ans = 1;
    while(n){
        ans *= 2;
        n--;
    }
    return ans;
}

int main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--){
	    int l, r;
	    cin>>l>>r;
	    if(r == l+2){
	        cout<<l<<" "<<l+1<<" "<<r<<endl;
	        continue;
	    }
	    int i, j, i_prime, j_prime;
	    i = log_base_2(l);
	    i_prime = i;
	    j = log_base_2(r);
	    j_prime = j;
	   // cout<<i<<" "<<j<<endl;
	   // int p = pow_2(i);
	    int l_prime = l;
	    int r_prime = r;
	   // cout<<pow_2(i_prime)<<" "<<j_prime<<endl;
	   // cout<<l_prime<<" "<<r_prime<<endl;
	   // int m = log_base_2(r_prime);
	   // cout<<i<<" "<<j<<" "<<m<<endl;
	   while(i_prime == j_prime && l_prime > 0 && r_prime > 0){
	       l_prime -= pow_2(i_prime);
	       r_prime -= pow_2(i_prime);
	       i_prime = log_base_2(l_prime);
	       j_prime = log_base_2(r_prime);
	   }
	   //cout<<i_prime<<" "<<j_prime<<endl;
	    if(j > i+1){
	        cout<<pow_2(j-1)<<" "<<pow_2(j)-1<<" "<<pow_2(j)<<endl;
	        continue;
	    }
	    if(j == i+1){
	        cout<<l<<" "<<pow_2(j)-1<<" "<<pow_2(j)<<endl;
	        continue;
	    }
	    if(j == i){
	       // l_prime to r_prime
	       if(j_prime > i_prime + 1){
	           cout<<l-l_prime+pow_2(j_prime-1)<<" "<<l-l_prime+pow_2(j_prime)-1<<" "<<l-l_prime+pow_2(j_prime)<<endl;
	           continue;
	       }
	       else if(j_prime == i_prime + 1){
	           cout<<l<<" "<<l-l_prime+pow_2(j_prime)-1<<" "<<l-l_prime+pow_2(j_prime)<<endl;
	           continue;
	       }
	    }
	}

}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int log_base_2(int n){
    if(n<=0)return -1;
    int ans = 0;
    while(n != 1){
        n /= 2;
        ans++;
    }
    return ans;
}

int pow_2(int n){
    if(n<=0)return -1;
    int ans = 1;
    while(n){
        ans *= 2;
        n--;
    }
    return ans;
}

int main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--){
	    int l, r;
	    cin>>l>>r;
	    if(r == l+2){
	        cout<<l<<" "<<l+1<<" "<<r<<endl;
	        continue;
	    }
	    if(l == 0 && r == 3){
	        cout<<0<<" "<<1<<" "<<2<<endl;
	    }
	    int i, j, i_prime, j_prime;
	    i = log_base_2(l);
	    i_prime = i;
	    j = log_base_2(r);
	    j_prime = j;
	   // cout<<i<<" "<<j<<endl;
	   // int p = pow_2(i);
	    int l_prime = l;
	    int r_prime = r;
	   // cout<<pow_2(i_prime)<<" "<<j_prime<<endl;
	   // cout<<l_prime<<" "<<r_prime<<endl;
	   // int m = log_base_2(r_prime);
	   // cout<<i<<" "<<j<<" "<<m<<endl;
	   while(i_prime == j_prime && l_prime > 0 && r_prime > 0){
	       l_prime -= pow_2(i_prime);
	       r_prime -= pow_2(i_prime);
	       i_prime = log_base_2(l_prime);
	       j_prime = log_base_2(r_prime);
	   }
	   //cout<<i_prime<<" "<<j_prime<<endl;
	    if(j > i+1){
	        cout<<pow_2(j-1)<<" "<<pow_2(j)-1<<" "<<pow_2(j)<<endl;
	        continue;
	    }
	    if(j == i+1){
	        cout<<l<<" "<<pow_2(j)-1<<" "<<pow_2(j)<<endl;
	        continue;
	    }
	    if(j == i){
	       // l_prime to r_prime
	       if(j_prime > i_prime + 1){
	           cout<<l-l_prime+pow_2(j_prime-1)<<" "<<l-l_prime+pow_2(j_prime)-1<<" "<<l-l_prime+pow_2(j_prime)<<endl;
	           continue;
	       }
	       else if(j_prime == i_prime + 1){
	           cout<<l<<" "<<l-l_prime+pow_2(j_prime)-1<<" "<<l-l_prime+pow_2(j_prime)<<endl;
	           continue;
	       }
	    }
	}

}