https://www.acmicpc.net/problem/2048

노가다를 좀 하다가 맞을 거 같아서 찍었다...

찍었다고 말하긴 했지만 사실상 수학적 직관력이 필요한 문제

아몰랑 노가다의 결과는 r >= 4이면, 마지막에 붙인 수를 2로 r만큼 나누면 홀수가 된다. 

따라서 r >= 4 일때는 r이 답이고, 다른 경우에는 수가 작으니 직접 다 붙여서 2로 몇번이나 나눠지는지 직접 나눠보면 된다.

 

#include <iostream>
#include <vector>
#include <cmath>
#define endl "\n"
using namespace std;

int t,l,r;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> t;
	while(t--){
		cin >> l >> r;
		if(r >= 4) {
			cout << r << endl;
			continue;
		}
		int num = 0;
		for(int i = r; i >= l; i--){
			num += (pow(2,i)*pow(10,r-i));
		}
		int cnt = 0;
		while(num % 2 == 0){
			num /= 2;
			cnt++;
		}
		cout << cnt << endl;
	}
}
루오