본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬]6627번 The Easiest Problem is This One

by 현장 2021. 4. 14.

-코드

while 1:
    n = int(input())
    s = 0
    n2 = n
    if n == 0:
        break
    while n2:
        s += n2 % 10
        n2 //= 10
    p = 11
    while 1:
        s2 = 0
        n3 = n * p
        while n3:
            s2 += n3 % 10
            n3 //= 10
        if s == s2:
            print(p)
            break
        p += 1

문제를 처음에 이해를 못해서 찾아보니 n의 각 자리수를 더한 수와 n × p의 각 자르 수를 더한 수가 같으면 p를 출력을 하는 것임을 알고 해결을 하였습니다.