2292번

김범주·2022년 7월 13일
0

백준 파이썬

목록 보기
11/29
post-thumbnail
import sys
input = sys.stdin.readline

N = int(input())
good = N//2
ans = 1000
# 1 7 19 37 61
# 0 6 12 18

#각 구간의 마지막 숫자 구하기
increase = [1]
for i in range(1, good):
  increase.append(i*6 + increase[-1])

for i in range(len(increase)):
  if N>increase[i] and N<=increase[i+1]:
    ans = i+2


if N == 1:
  print(1)
elif N <= 7:
  print(2)
elif N <= 19:
  print(3)
else:  
  print(ans)    

이동 횟수가 바뀌는 구간을 찾으면 1, 7, 19, 37....
인덱스와 첫 번째 숫자의 차이로 인한 2를 더해주고 19 까지는 적용이 안되므로 따로 분기
예제는 잘 통과하지만 코드가 너무 길어 실패..

정답

n=int(input())
count=1
num=1
while True:
    if num>=n:
        break
    num+=6*count
    count+=1
print(count)

num을 1로 두고 6의 배수를 더해가는 구조로 가다가 n이상이 되면 멈추는 while문으로 해서 양을 확 줄여서 통과

profile
개발꿈나무

0개의 댓글