Under construction

Still being built. Things may change

Balanced Ternary

Interview

Time limit1sMemory limit1024 MB

Summary
Convert a decimal integer between -10^9 and 10^9 into its unique balanced ternary representation, printing -1 digits as the letter T.
Level

Medium4 of 10

Topics
Math, Implementation, Number theory, String
Solved
No attempts yet

Problem

Balanced ternary is a base-33 numeral system whose digits are 00, 11, and −1-1.

With it, every integer can be represented in exactly one way without using a separate sign.

Write a program that reads a decimal number and prints it in balanced ternary.

Input

An integer NN in decimal notation is given.

Output

Print the answer. If a digit is −1-1, print 'T' instead.

Constraints

  • −109≤N≤109-10^9 \le N \le 10^9

Hint

10=1×32+0×31+1×3010 = 1\times 3^2+0\times 3^1 + 1\times 3^0

5=1×32+(−1)×31+(−1)×305 = 1\times 3^2+(-1)\times 3^1 + (-1)\times 3^0

−8=(−1)×32+0×31+1×30-8 = (-1)\times 3^2+0\times 3^1 + 1\times 3^0

Examples3

  1. Example 1

    Input
    10
    
    Expected output
    101
    
  2. Example 2

    Input
    5
    
    Expected output
    1TT
    
  3. Example 3

    Input
    -8
    
    Expected output
    T01