-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1052.java
More file actions
38 lines (33 loc) · 987 Bytes
/
Copy path1052.java
File metadata and controls
38 lines (33 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// https://www.acmicpc.net/problem/1052
// BOJ 1052 물병
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(scan.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[] hand = new int[k];
for(int i=0; i<k; i++){
int l = get_biggist(n);
hand[i] = l;
n -= l;
if(n <= 0){
System.out.println(0);
return;
}
}
int answer = hand[k-1] - n;
System.out.println(answer);
}
public static int get_biggist(int n){
int pow = 1;
while(pow < n){
pow *= 2;
}
if(pow == n) return pow;
else return pow/2;
}
}