반응형
SMALL
# 풀이 - 수학 이용
- 연속된 자연수가 2개일 때, 3개일 때 ... 쭉 검사한다.
import java.util.*;
public class Main {
public int solution(int n) {
int answer =0;
int cnt =1;
// 어차피 1 뺴야되니까 1 빼줌
n--;
while(n>0) {
cnt++;
n = n-cnt;
if(n%cnt==0) answer++;
}
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
System.out.print(T.solution(n));
}
}
반응형
LIST
'자바 알고리즘' 카테고리의 다른 글
21. 아나그램(해쉬) (0) | 2022.09.13 |
---|---|
20. 학급회장 (HashMap) (0) | 2022.09.12 |
18. 연속된 자연수의 합 (0) | 2022.08.09 |
17. 연속 부분 수열 (sliding window + 복합) (0) | 2022.08.08 |
16. 최대 매출 (Sliding window) (0) | 2022.08.08 |
댓글