Skip to content

Commit 4c88a8b

Browse files
committed
[BOJ]정수 제곱근/실버4/1시간
1 parent f3fce7e commit 4c88a8b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//BOJ2417 정수 제곱근, 실버4
2+
//처음에는 이 문제와 이분탐색이 어떤 접점이 있는지 이해하기 어려웠음
3+
// 1번 방법 Math.sqrt
4+
// 2번 방법 이분 탐색 - 이걸로 품
5+
import java.io.*;
6+
7+
public class BOJ2417 {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
long num = Long.parseLong(br.readLine());
12+
13+
long start = 0;
14+
long end = num;
15+
long ans = 0;
16+
17+
while(start <= end) {
18+
long mid = (start+end) / 2;
19+
if(num <= Math.pow(mid, 2)) {
20+
ans = mid;
21+
end = mid-1;
22+
} else {
23+
start = mid+1;
24+
}
25+
}
26+
27+
bw.write(ans+"\n");
28+
bw.flush();
29+
bw.close();
30+
br.close();
31+
}
32+
}

0 commit comments

Comments
 (0)