import java.util.Scanner;
import java.math.BigInteger;
class Main {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
while(in.hasNext()){
String s1,s2;
s1=in.next();
s2=in.next();
int i=0,j=0,l=0;
int val=0,flag=0;
for(int k=0;k<s1.length();k++){
if(s1.charAt(k)>val)
val=s1.charAt(k);
}
if(val>='0'&&val<='9')
i=val-'0'+1;
else
i=val-'A'+11;
val=0;
for(int k=0;k<s2.length();k++){
if(s2.charAt(k)>val)
val=s2.charAt(k);
}
if(val>='0'&&val<='9')
j=val-'0'+1;
else
j=val-'A'+11;
if(i==1&&j==1){
flag=1;
i=2;
l=2;
j=2;
}
if(i==1||j==1)
flag=2;
for(;i<37&&flag<1;i++)
for(l=j;l<37&&flag<1;l++){
BigInteger a=new BigInteger(s1,i);
BigInteger b=new BigInteger(s2,l);
if(a.equals(b)){
flag=1;
i--;
break;
}
}
if(flag==1)
System.out.println(s1+" (base "+i+") = "+s2+" (base "+l+")");
else
System.out.println(s1+" is not equal to "+s2+" in any base 2..36");
}
}
}
import java.math.BigInteger;
class Main {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
while(in.hasNext()){
String s1,s2;
s1=in.next();
s2=in.next();
int i=0,j=0,l=0;
int val=0,flag=0;
for(int k=0;k<s1.length();k++){
if(s1.charAt(k)>val)
val=s1.charAt(k);
}
if(val>='0'&&val<='9')
i=val-'0'+1;
else
i=val-'A'+11;
val=0;
for(int k=0;k<s2.length();k++){
if(s2.charAt(k)>val)
val=s2.charAt(k);
}
if(val>='0'&&val<='9')
j=val-'0'+1;
else
j=val-'A'+11;
if(i==1&&j==1){
flag=1;
i=2;
l=2;
j=2;
}
if(i==1||j==1)
flag=2;
for(;i<37&&flag<1;i++)
for(l=j;l<37&&flag<1;l++){
BigInteger a=new BigInteger(s1,i);
BigInteger b=new BigInteger(s2,l);
if(a.equals(b)){
flag=1;
i--;
break;
}
}
if(flag==1)
System.out.println(s1+" (base "+i+") = "+s2+" (base "+l+")");
else
System.out.println(s1+" is not equal to "+s2+" in any base 2..36");
}
}
}
Comments
Post a Comment