728x90
반응형
입력 자신을 제외한 약수들을 리스트에 저장하고 리스트의 합이 입력과 같은지 확인하면 된다.
while 1:
n = int(input())
if n == -1:
break
li = []
for i in range(2, n//2+1):
if n % i == 0:
li.append(i)
if sum(li) + 1 == n:
print('{0} = 1 '.format(n), end = '')
for j in li:
print('+ {0} '.format(j) ,end = '')
else:
print('{0} is NOT perfect. '.format(n))
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 9550번 아이들은 사탕을 좋아해(python) (0) | 2020.02.13 |
---|---|
백준 알고리즘 9546번 3000번 버스(python) (0) | 2020.02.13 |
백준 알고리즘 9488번 시험 성적(python) (0) | 2020.02.13 |
백준 알고리즘 9375번 패션왕 신해빈(python) (0) | 2020.02.13 |
백준 알고리즘 9086번 문자열(python) (0) | 2020.02.13 |