본문 바로가기

code/BOJ

백준 1011 Fly me to the Alpha Centauri

 

 

로그인

 

www.acmicpc.net

#include <iostream>
using namespace std;
int T, x, y;
unsigned int sq[46343];
int main() {
	for (int i = 0; i < 46343; ++i) {
		sq[i] = i * i;
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> T;
	while (T--) {
		cin >> x >> y;
		int n = y - x;
		for (int i = 0; i < 46342; ++i) {
			if (sq[i] >= n) {
				if (sq[i - 1] + i - 1 >= n) {
					cout << i * 2 - 2 << '\n';
				}
				else {
					cout << i * 2 - 1 << '\n';
				}
				break;
			}
		}
	}
	return 0;
}