서로 다른 N개의 자연수의 합이 S라고 한다. S를 알 때, 자연수 N의 최댓값은 얼마일까?
1 => 1 (1)
2 => 2 (1)
3 => 1, 2 (2)
4 => 1, 3 (2)
5 => 1, 4 (2)
6 => 1, 2, 3 (3)
...
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long S = scanner.nextLong();
long count = 0;
while (S > count) {
count++;
S -= count;
}
System.out.println(count);
}
}