-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ2018.java
More file actions
50 lines (41 loc) · 732 Bytes
/
Copy pathBOJ2018.java
File metadata and controls
50 lines (41 loc) · 732 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
39
40
41
42
43
44
45
46
47
48
49
50
package day1.array;
import java.util.Scanner;
public class BOJ2018 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int start=1, end=1;
int cnt=0, sum=0;
while(end<N+1) {
if(sum==N) {
cnt++;
start++;
end++;
sum-=start-1;
sum+=end;
}else if(sum<N) {
end++;
sum+=end;
}else if(sum>N) {
start++;
sum-=start-1;
}
}
// int[] arr=new int[N];
// for (int i = 0; i < N; i++) {
// arr[i]=i+1;
// }
// int cnt=0;
// for (int i = 0; i < N; i++) {
// int sum=0;
// for (int j = i; j < N; j++) {
// sum+=arr[j];
// if(sum==N) {
// cnt+=1;
//
// }
// }
// }
// System.out.println(cnt);
}
}