public class Country124 {
public String solution(int n) {
String answer = "";
int mok = -1, na = 0;
while (mok != 0) {
na = n % 3;
mok = n / 3;
if (na == 0) {
na = 3;
mok -= 1;
}
answer = ((na == 3) ? Integer.toString(na + 1) : Integer.toString(na)) + answer;
n = mok;
}
return answer;
}
public String solution1(int n) {
String answer = "";
String[] arr = { "4", "1", "2" };
while (n > 0) {
answer = arr[n % 3] + answer;
n = (n - 1) / 3;
}
return answer;
}
public static void main(String[] args) {
Country124 s = new Country124();
System.out.println(s.solution(1));
System.out.println(s.solution(2));
System.out.println(s.solution(3));
System.out.println(s.solution(4));
System.out.println(s.solution(5));
System.out.println(s.solution(6));
System.out.println(s.solution(7));
System.out.println(s.solution1(8));
System.out.println(s.solution1(9));
System.out.println(s.solution1(10));
System.out.println(s.solution1(11));
System.out.println(s.solution1(12));
System.out.println(s.solution1(13));
System.out.println(s.solution1(14));
System.out.println(s.solution1(15));
System.out.println(s.solution1(16));
}
}