The merchants of the Sept Isles keep their trade ledgers using a seven-symbol numeral system: every amount is written using only the digits 0 through 6, with each position worth seven times the position to its right (a base-7 positional system). A debt is written with a leading minus sign.
Given a signed integer trade amount, write it exactly as it would appear in a Sept Isles ledger.
A single line containing one integer n (-10000000 ≤ n ≤ 10000000).
Print the seven-symbol ledger notation of n: the base-7 digits of |n| with no leading zeros (except that zero itself is printed as 0), prefixed with a single - if n is negative.
Example 1
Input
100
Expected
202
Explanation
100 = 2×49 + 0×7 + 2×1, i.e. 2×7² + 0×7¹ + 2×7⁰, so the base-7 digits are 2, 0, 2, giving "202".
Example 2
Input
-8
Expected
-11
Explanation
8 = 1×7 + 1, so its base-7 digits are 1, 1 ("11"). Since the original amount is negative (a debt), the ledger notation prefixes a minus sign, giving "-11".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →