| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 3152 |
| 문제명 | 예쁜 숫자 |
| 레벨 | 실버 2 |
| 분류 |
애드혹 |
| 시간복잡도 | O(logn / logp) |
| 인풋사이즈 | n<10^18 |
| 사용한 언어 | Python 3.11 |
| 제출기록 | 31120KB / 40ms |
| 최고기록 | 40ms |
| 해결날짜 | 2024/01/23 |
"""Solution code for "BOJ 3152. 예쁜 숫자".
- Problem link: https://www.acmicpc.net/problem/3152
- Solution link: http://www.teferi.net/ps/problems/boj/3152
Tags: [ad hoc]
"""
def is_pretty(n, p):
count = [0] * 3
while n:
n, m = divmod(n, p)
if m > 2:
return False
count[m] += 1
return (count[1] == 1 and count[2] > 0) or (count[1] == 2 and count[2] == 0)
def main():
p, *n = [int(x) for x in input().split()]
print(' '.join('1' if is_pretty(n_i, p) else '0' for n_i in n))
if __name__ == '__main__':
main()