import java.io.*;

public class Numeral
{
    // Given an integer, return its decimal representation
    public static String decimal(int n) {
	String s = "";
	while (n != 0) {
	    s = "0123456789".charAt(n%10) + s;
	    n /= 10;
	}
	return s;
    }

    // Given an integer, return its octal representation
    public static String octal(int n) {
	String s = "";
	while (n != 0) {
	    s = "01234567".charAt(n%8) + s;
	    n /= 8;
	}
	return s;
    }

    // Given an integer, return its binary representation
    public static String binary(int n) {
	String s = "";
	while (n != 0) {
	    s = "01".charAt(n%2) + s;
	    n /= 2;
	}
	return s;
    }

    // Given an integer, return its hexadecimal representation
    public static String hexadecimal(int n) {
	String s = "";
	while (n != 0) {
	    s = "0123456789abcdef".charAt(n%16) + s;
	    n /= 16;
	}
	return s;
    }

    // Given an integer n, returns is representation in base b
    // We assume 1 < b <= 16
    public static String convert(int n, int b) {
	String s = "";
	while (n != 0) {
	    s = "0123456789abcdef".charAt(n%b) + s;
	    n = n / b;
	}
	return s;
    }

    public static void main(String[] args) {
	System.out.println(decimal(357));
	System.out.println(octal(357));
	System.out.println(binary(357));
	System.out.println(hexadecimal(357));
	System.out.println(convert(357, 10));
	System.out.println(convert(357, 8));
	System.out.println(convert(357, 2));
	System.out.println(convert(357, 16));
    }
}
