def solution(n):
answer = ''
ch=['0','1','2','4']
lst=[4,1,2]
if n<=3:
return ch[n]
for i in range(4,n+1):
if i%3==0:
ch.append(str(ch[(i//3)-1])+str(lst[i%3]))
else:
ch.append(str(ch[i//3])+str(lst[i%3]))
answer=ch[-1]
return answer
# 답은 나왔으나 시간초과로 효율성이 떨어지는 방법
def solution(n):
if n<=3:
return '124'[n-1]
else:
q, r = divmod(n-1, 3)
return solution(q) + '124'[r]