homework3.py 287 B

1234567891011121314151617
  1. """Задача Дважды Три"""
  2. number = int(input())
  3. def ternary(num: int) -> int:
  4. if num == 0:
  5. return 0
  6. s = ""
  7. while num:
  8. s += str(num % 3) + str(num % 3)
  9. num //= 3
  10. encoded = s[::-1]
  11. return int(encoded, 3)
  12. print(ternary(number))