RUBY

[백준] 수들의 합 본문

PS/BOJ

[백준] 수들의 합

RUBY_루비 2020. 9. 26. 23:59

출처:: www.acmicpc.net/problem/1789

분류:: 

 

1. 문제 이해 및 해결과정

 

2. 풀이방법

  1. 

#수들의 합
#https://www.acmicpc.net/problem/1789
import sys
sys.stdin = open("input.txt","r")
n=int(input())
#x(x+1)/2 = n
x=1
while(x*(x+1)/2 <=n):
    x+=1
print(x-1)

  2.

#수들의 합
#https://www.acmicpc.net/problem/1789
import sys
sys.stdin = open("input.txt","r")
n=int(input())
#x(x+1)/2 = n
num,sum=1,0
cnt=0
while True:
    sum+=num
    cnt+=1
    if sum>n:
        break
    num+=1
print(cnt-1)

 

3. 오답원인

 

4. 알게된 점

 

'PS > BOJ' 카테고리의 다른 글

[백준] 에디터  (0) 2020.09.28
[백준] 격자상의 경로  (0) 2020.09.27
[백준] 동전2  (0) 2020.09.26
[백준] 1로 만들기  (0) 2020.09.26
[백준] 꽃잎  (0) 2020.09.24
Comments