πŸ“• Algorithm/Solved

[λ°±μ€€] 4673 μ…€ν”„ λ„˜λ²„ (파이썬3 Python3)

ν•œμ½”λ”© 2020. 10. 2. 17:50
728x90
728x90
# 1λΆ€ν„° 10000κΉŒμ§€ 숫자 μ €μž₯
num_set = set(range(1, 10001))

# μ…€ν”„ λ„˜λ²„κ°€ μ•„λ‹Œ 수λ₯Ό μ €μž₯
not_self_num= set()

for i in range(1, 10001):
    for j in str(i): # 숫자λ₯Ό λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•˜μ—¬ 102이면 1, 0, 2둜 μ ‘κ·Ό
        i += int(j)  # d(i) = i + j1 + j2 + j3 + .. = 102 + 1 + 0 + 2

    not_self_num.add(i) # μ…€ν”„ λ„˜λ²„κ°€ μ•„λ‹Œ 수 μ €μž₯

# μ…€ν”„ λ„˜λ²„λ§Œ μžˆλŠ” set = 전체 수 set - μ…€ν”„ λ„˜λ²„κ°€ μ•„λ‹Œ 수 set
self_num = num_set - not_self_num

# μ˜€λ¦„μ°¨μˆœμœΌλ‘œ μ •λ ¬ ν›„ 좜λ ₯
for i in sorted(self_num):
    print(i)
728x90
λ°˜μ‘ν˜•