What I Learned/Algorithm Practice
[백준 - python] 4673번: 셀프 넘버
Interrobang
2022. 3. 14. 15:53
<문제 링크>
4673번: 셀프 넘버
셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때,
www.acmicpc.net
<문제 풀이>
num = set(range(1, 10000))
remove_set = set()
for i in num:
for n in str(i):
i += int(n)
remove_set.add(i)
self_numbers = num - remove_set
for j in sorted(self_numbers):
print(j)

...

*key point: 셀프 넘버가 아닌 수들을 제거함으로써 셀프 넘버를 찾는다. 중복 요소가 없도록하는 set 함수와 이에 맞는 메서드를 활용한다.