수들의 합 5 2018

LJM·2023년 2월 27일
0

백준풀기

목록 보기
118/259

https://www.acmicpc.net/problem/2018

첨에 left 1 right 2 로 시작했다가 틀렸다

N 자기자신도 사용할 수 있다는 사실!

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;
        int right = 0;
        int ans = 0;
        int sum = left+right;
        while(true)
        {

            if(sum == N)
                ans++;

            if(sum > N)
            {
                sum -= left;
                left++;
            }
            else//sum <= N
            {
                right++;
                sum += right;

                if(right > N)
                    break;
            }
        }

        System.out.println(ans);

    }
}
profile
게임개발자 백엔드개발자

0개의 댓글