Created
January 6, 2020 14:13
-
-
Save inspirit941/42add1f9ee29c9ad9189d92dc3f9f29e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
num = sys.stdin.readline() | |
# 생성자가 존재할 수 있는 숫자인지 확인하기. | |
possible_start = int(num) - (len(num)*9) | |
if possible_start < 0: | |
possible_start = int(num) | |
# 생성자가 존재할 수 있는 숫자인 경우 | |
while possible_start < int(num): | |
# 각 자릿수의 합을 계산한다. | |
each_num_sum = sum([int(i) for i in str(possible_start)]) | |
# 분해합 = 생성자 + 각 자릿수의 합 | |
result = possible_start + each_num_sum | |
# 값이 있으면 해당 생성자를 출력한다. | |
if result == int(num): | |
print(possible_start) | |
break | |
else: | |
# 생성자를 찾을 때까지 값을 더해준다. | |
possible_start += 1 | |
if possible_start == int(num): | |
print(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment