def solution(n): answer = 0 temp = [] while n != 0: n, x = divmod(n,3) temp.append(x) for i in range(len(temp)): answer += (3**i)*temp[len(temp)-1-i] return answer