백준. 2231번. 분해합 파이썬 풀이

minan·2021년 6월 29일
0

프로그래머스

목록 보기
85/92

백준. 2231번. 분해합 파이썬 풀이

문제링크 https://www.acmicpc.net/problem/2231

n = int(input())

# n의 반부터 n까지 반복
for i in range(n//2, n):
    temp = i
    array = list(str(i))
    # 각 자리수를 더함
    for j in range(len(array)):
        temp += int(array[j])
    # i가 n의 생성자라면 출력하고 break
    if temp == n:
        print(i)
        break
# 반복문을 끝까지 돌렸는데도 생성자라 존재하지 않는다면 0 출력
else:  
    print(0)
profile
https://github.com/minhaaan

0개의 댓글