From 46d744f07d94c48c2a610b3d19ed421c83e85c52 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Wed, 17 Sep 2025 19:23:43 +0900 Subject: [PATCH] =?UTF-8?q?[20250917]=20BOJ=20/=20G5=20/=20Fly=20me=20to?= =?UTF-8?q?=20the=20Alpha=20Centauri=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../17 BOJ G5 Fly me to the Alpha Centauri.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lkhyun/202509/17 BOJ G5 Fly me to the Alpha Centauri.md diff --git a/lkhyun/202509/17 BOJ G5 Fly me to the Alpha Centauri.md b/lkhyun/202509/17 BOJ G5 Fly me to the Alpha Centauri.md new file mode 100644 index 00000000..58c2cd92 --- /dev/null +++ b/lkhyun/202509/17 BOJ G5 Fly me to the Alpha Centauri.md @@ -0,0 +1,40 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws Exception { + int T = Integer.parseInt(br.readLine()); + + for (int i = 0; i < T; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + int diff = (y-x); + int cnt = 1; + + + double candidate = Math.sqrt(diff); + int temp = (int)candidate; + if(candidate*candidate == temp*temp) { + bw.write((temp*2 - 1)+"\n"); + continue; + }else{ + cnt = temp; + } + + int rest = diff - cnt*cnt; + if(rest>cnt) bw.write((cnt*2 + 1) + "\n"); + else bw.write((cnt*2)+"\n"); + } + + bw.close(); + } + +} +```