y - x | 이동 | 이동횟수 |
---|---|---|
1 | 1 | 1 |
2 | 11 | 2 |
3 | 111 | 3 |
4 | 121 | 3 |
5 | 1211 | 4 |
6 | 1221 | 4 |
7 | 12211 | 5 |
8 | 12221 | 5 |
9 | 12321 | 5 |
각각의 제곱수들 기준으로 특정 규칙이 보인다
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int a;long long b, c; cin >> a;
for (int i = 0;i < a;i++) {
cin >> b >> c;
long long d = (long long)sqrt(c-b);
if (sqrt(c - b) > d + 0.5) d += 1;
if (d * d < (c - b))
cout << d + d<< "\n";
else
cout << d + d - 1 << "\n";
}
}