File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
junsu/week11/BOJ2417 정수 제곱근 Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments