import java.io.*;
import java.lang.*;

class basen {
	// gets an integer on a line by itself from the
	// standard input stream
	public static int getNumber() throws IOException{
		BufferedReader input = new BufferedReader (new
                  InputStreamReader(System.in));
		return Integer.parseInt(input.readLine());
	}

	// converts an arbitrary base (<10) number to human
	// (base 10) terms for computation
	public static int toHuman(int number, int base){
		int mod=0;
		int place=0;
		int ten=0;
		while(number > 0){
			mod = number%10;
			number = number/10;
			ten = ten + mod * (int)Math.pow(base,place);
			place++;
		}
		return ten;			
	}

	// gets two numbers with their bases and computes their ratio
	public static void main(String[] args) throws IOException{
		System.out.println("Enter the base of the first number.");
		int base1 = getNumber();
		System.out.println("Enter the number.");
		int number1 = getNumber();
		System.out.println("Enter the base of the second number");
		int base2 = getNumber();
		System.out.println("Enter the number.");
		int number2 = getNumber();
		int converted1 = toHuman(number1,base1);
                System.out.println("1st number: "+converted1);
		int converted2 = toHuman(number2,base2);
                System.out.println("2nd number: "+converted2);
                float ratio = (float)converted1/(float)converted2;
                System.out.println("Ratio of "+number1+"["+base1+"] : "+
                  number2+"["+base2+"] is "+ratio);
	}
}

