[내배캠/TIL(8/4)/Python]백준 알고리즘 4637번

손홍서·2022년 8월 4일
0

day73

백준 4637번

백준 4637번으로 가기

처음 풀었을때.. 제출하고 보니 뭔가 더 효율적으로 풀 수 있을 것 같다.

no_self_num = list()
division = [1000, 100, 10, 1]

for n in range(1, 10000 + 1):
      result = n
      
      for d in division:
            result += n // d
            n = n % d

      if result > 10000:
            continue

      no_self_num.append(result)

for n in range(1, 10000 + 1):
      if n not in no_self_num:
            print(n)
no_self_num = set() # 중복 없이 저장 가능

def d(n):
      n =n + sum(map(int, str(n))) # sum(map(int, str(n))) 각 자리의 숫자들의 합을 구할 수 있다.
      return n

for n in range(1, 10000 + 1):
      no_self_num.add(d(n))

for n in range(1, 10000 + 1):
      if n not in no_self_num:
            print(n)
  • 중복없이 저장하도록 set을 이용
  • sum(map(int, str(n))) 로 각 자리의 숫자들의 합을 구함

참고자료
https://kbwplace.tistory.com/69

profile
Hello World!!

0개의 댓글