import java.io.*; import java.util.*; import java.math.*; class Main{ void sol() { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); while(in.hasNext()) { String a=in.next(); String b=in.next(); BigInteger b1,b2; boolean f=false; for(int i=2; i<=36; i++) { try{ b1=new BigInteger(a,i); } catch(Exception e) { continue; } for(int j=2; j<=36; j++) { try{ b2= new BigInteger(b,j); } catch(Exception e) { continue; } if(b1.compareTo(b2)==0){ f=true; System.out.println(a + " (base " + i + ") = " + b + " (base " + j + ")"); break; } } if(f) break; } if(!f) System.out.println(a + " is not equal to " + b + " in any base 2..36"); } } public static void main(String args[]) { Main uva343 = new Main(); uva343.sol(); } }
Wednesday, November 2, 2016
UVa 343
Labels:
UVA Solution
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Thank you for commenting. Please wait for response :)