Playground/자바문제집

[백준] 2018번

미숫가루설탕많이 2023. 4. 4. 22:42

 

 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 1, startIndex = 1, endIndex = 1, sum = 1;

        while(endIndex != N) {
            if (sum == N) {
                count++;
                endIndex++;
                sum += endIndex;
            } else if (sum > N) {
              sum -= startIndex;
              startIndex++;
            } else {
                endIndex++;
                sum += endIndex;
            }
        }

        System.out.println(count);
    }
}

'Playground > 자바문제집' 카테고리의 다른 글

[백준] 12891번  (0) 2023.04.05
[백준] 1940번  (0) 2023.04.05
[프로그래머스] 숫자의 표현  (0) 2023.03.30
[프로그래머스] 이진 변환 반복하기  (0) 2023.03.30
[프로그래머스] 최솟값 만들기  (0) 2023.03.30