//ISC 2004
public class BaseSame2numbers
{   private static int toDecimal(String n, int b)
    {   int res=0, p=0;
        for(int i=n.length()-1; i>=0; i--)
        {   char ch=n.charAt(i);
            int val=ch<=57?ch-48:ch-55;
            if(val>=b) return -1; //invalid digit in nuber
            res+=val*(int)Math.pow(b,p++);
        }
        return res;
    }//toDecimal
    public static void main(String args[])
    {   String n1="2", n2="10"; //input the numbers E.g. A;10, 1
        outer:for(int i=2; i<=20; i++)//base ranges from 2-20
        {   if(toDecimal(n1,i)==-1) continue;
            for(int j=2; j<=20; j++)
            {   if(toDecimal(n2,j)==-1) continue;
                if(toDecimal(n1,i)==toDecimal(n2,j))
                {   System.out.println(n1+" = "+i);
                    System.out.println(n2+" = "+j);
                    break outer;
                }
            }
        }
    }//main
}

