BackJoon Algorithm 수들의 합 1789 (Java)

업데이트:
최대 1 분 소요

BackJoon Algorithm - Java

alt

문제

alt

풀이

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Back_1789 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Long S = Long.parseLong(br.readLine());
        Long sum = 0L;
        Long count = 0L;
        for (Long i = 1L; ; i++) {
            if(sum > S){
                break;
            }
            else{
                sum += i;
                count ++;
            }
        }
        System.out.println(count - 1);
        br.close();
    }
}

댓글남기기