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

[백준/파이썬] 14561번 회문

by 현장 2022. 7. 5.

-Code

def convert(N, base):
    nums = "0123456789ABCDEF"
    answer = ""
    while N > 0:
        answer += nums[N % base]
        N //= base
    return answer[::-1]


for _ in range(int(input())):
    a, n = map(int, input().split())
    res = convert(a, n)
    print(1 if res == res[::-1] else 0)

10진법 이상일 경우를 생각 못해서 시간이 좀 걸렸습니다.