-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_2018.java
More file actions
34 lines (30 loc) · 864 Bytes
/
Copy pathBOJ_2018.java
File metadata and controls
34 lines (30 loc) · 864 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
// BOJ - 2018
// Problem Sheet - https://www.acmicpc.net/problem/2018
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int left = 0, right = 0;
int sum = 0;
int answer = 0;
while(left <= right && right <= n) {
if(sum == n) {
sum -= left;
left++;
right++;
sum += right;
answer++;
} else if(sum < n) {
right++;
sum += right;
} else {
sum -= left;
left++;
}
}
System.out.println(answer);
br.close();
System.exit(0);
}
}