STUDY/Algorithm
[백준] 2231 분해합
sinawi95
2021. 2. 20. 21:23
728x90
https://www.acmicpc.net/problem/2231
2231번: 분해합
어떤 자연수 N이 있을 때, 그 자연수 N의 분해합은 N과 N을 이루는 각 자리수의 합을 의미한다. 어떤 자연수 M의 분해합이 N인 경우, M을 N의 생성자라 한다. 예를 들어, 245의 분해합은 256(=245+2+4+5)이
www.acmicpc.net
N=int(input())
result = 0
try:
for n in range(N-54,N):
temp = n
for ch in str(n):
temp += int(ch)
if temp == N:
result = n
break
else:
result = 0
except:
pass
print(result)
알고리즘 문제풀때 try, except를 사용하지 말라했지만 너무 귀찮아서 한번 사용했는데 통과되었다.