[백준 2635][Python] 수 이어가기

봉글렛·2023년 1월 1일

백준

목록 보기
14/55

문제 링크 https://www.acmicpc.net/problem/2635
두번째 수를 증감 연산 하면서 구한다

풀이

n = int(input())
s = 0
l_max = []

while True:
    a = [n, n-s]
    count = 0
    while True:
        next_n = a[-2]-a[-1]
        if next_n < 0:
            break
        a.append(next_n)
    if len(l_max) <= len(a):
        l_max = a
        s += 1
    else:
        break
print(len(l_max))
for i in l_max:
    print(i, end=' ')
profile
어쩌다 개발자 (할 수 있을 때까지!!!!)

0개의 댓글