Here, we consider the base three representation of the natural numbers. For example, 59 is represented as 2012, because . Note that all digits are between 0 and 2, and that we have no zeros on the left.
Write a program to print the result of rearranging the base three digits of each given number, so that the result is the maximum possible, with an additional condition: we cannot have two equal consecutive digits.
Input consists of several , all between 1 and .
For every given , print its base three digit rearrangement without equal adjacent digits that produces the maximum possible result. If no reordering is possible, tell so.
Author: Salvador Roura
Generation: 2026-01-25T11:05:45.896Z
© Jutge.org, 2006–2026.
https://jutge.org