https://www.acmicpc.net/problem/1789
1789번: 수들의 합
첫째 줄에 자연수 S(1 ≤ S ≤ 4,294,967,295)가 주어진다.
www.acmicpc.net
문제
서로 다른 N개의 자연수의 합이 S라고 한다. S를 알 때, 자연수 N의 최댓값은 얼마일까?
입력
첫째 줄에 자연수 S(1 ≤ S ≤ 4,294,967,295)가 주어진다.
출력
첫째 줄에 자연수 N의 최댓값을 출력한다.
예제 입력
200
예제 출력
19
Solution
Python
# ver.1
N = int(input())
for i in range(1,92683):
N -= i
if N < i+1 or N <= 0:
break
print(i)
# ver.2
N = int(input())
sum = 0
for i in range(1,92683):
sum += i
if sum > N:
break
print(i-1)
#ver.3
i = 0
S = int(input())
while i < S:
S = S - i
i += 1
if S >= i:
print(i)
else:
print(i-1)
#ver.4
N = int(input())
cnt = 0
cnt1 = 0
if N == 1 or N == 2:
print(1)
exit()
elif N == 3:
print(2)
exit()
for i in range(1, N):
cnt += i
cnt1 += 1
if cnt > N:
break
print(cnt1-1)
#ver.5 (공개코드)
print(int(((int(input())*8+1)**.5-1)/2))
'메모장 > 백준 온라인 저지(BOJ)' 카테고리의 다른 글
백준 4796번 - 캠핑 (0) | 2021.11.10 |
---|---|
백준 2891번 - 카약과 강풍 (0) | 2021.11.10 |
백준 17626번 - Four Squares (0) | 2021.11.09 |
백준 16471번 - 작은 수 내기 (0) | 2021.11.09 |
백준 16173번 - 점프왕 쩰리 (0) | 2021.11.08 |