π»λμ νμ΄
//λ¨μ 거리, μ κ³±μμΌλ
function sqrtDistance (x, y) {
//λ¨μ μ΄λ 거리
const distance = y - x;
//거리μ μ κ³±κ·Ό
const squareRoot = Math.sqrt(distance);
return squareRoot % 1 == 0 ? squareRoot * 2 - 1 : notSqrt(distance, squareRoot);
}
//κ±°λ¦¬κ° μ κ³±μκ° μλλΌλ©΄
function notSqrt (distance, squareRoot) {
const ceilSqrt = Math.ceil(squareRoot);
const floorSqrt = Math.floor(squareRoot)
const median = ceilSqrt ** 2 - floorSqrt;
return distance < median ? floorSqrt * 2 : floorSqrt * 2 + 1;
}
function main () {
// let input = require('fs').readFileSync('/dev/stdin').toString().split('\n');
const input = require('fs').readFileSync('txt/1011.txt').toString().split('\n');
const test = +input[0];
for (let i = 1; i <= test; i++) {
const [x, y] = input[i].split(' ').map(Number);
const result = sqrtDistance(x, y);
console.log(result);
}
}
main();
β거리λ₯Ό μ κ³±μλ§λ€ λλ λ¬Άμ΄μ λ³Έλ€.(μ κ³±μ : squareRoot % 1 == 0)
πμ κ³±μμ λ€μ μ«μμμ μ΄λ νμκ° μ¦κ°νλ€.
πλ¬ΆμΈ μ«μλ€μ μ€κ°κ°(median)μμ μ΄λ νμκ° μ¦κ°νλ€.