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

[백준/파이썬] 15296번 Sum Squared Digits Function

by 현장 2023. 7. 5.

-Code

for _ in range(int(input())):
    arr = []
    k, b, n = map(int, input().split())

    while n:
        arr.append(n % b)
        n //= b

    res = 0

    for a in arr:
        res += a ** 2

    print(k, res)