[BOJ 1789] ์ˆ˜๋“ค์˜ ํ•ฉ

 

1. ๋ฌธ์ œ : Link

ํŠน์ • ์ž์—ฐ์ˆ˜๋ฅผ ์ด๋ฃจ๋Š” ๊ฐ’์˜ ์ตœ๋Œ€

 

2. ํ’€์ด

1๋ถ€ํ„ฐ ํ•ด๋‹น ๊ฐ’์—์„œ ๋นผ์ฃผ๋ฉด์„œ 0์ด ๋˜๊ฑฐ๋‚˜ ์Œ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฐ’์„ return ํ˜น์€ -1 ํ•ด์„œ return

 

3. ์ฝ”๋“œ

n = int(input())
result = 0
cnt = 0

if n == 1 or n == 2:
  result = 1
else:  
  for i in range(1, n):
    n = n - i
    if n == 0 :
      result = i
      break
    elif n < 0:
      result = i - 1
      break

print(result)

 

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ