Skip to content

Commit

Permalink
343 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
ksaveljev committed Oct 18, 2011
1 parent 4ad534c commit a2f2777
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions 343.java
@@ -0,0 +1,54 @@
import java.io.*;
import java.util.*;
import java.math.*;

class Main
{
void solve()
{
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

while (in.hasNext())
{
String a = in.next();
String b = in.next();
boolean found = false;
BigInteger biga, bigb;

for (int i = 2; i <= 36; i++) {
try {
biga = new BigInteger(a, i);
} catch (Exception e) {
continue;
}

for (int j = 2; j <= 36; j++) {
try {
bigb = new BigInteger(b, j);
} catch (Exception e) {
continue;
}

if (biga.compareTo(bigb) == 0) {
found = true;
System.out.println(a + " (base " + i + ") = " + b + " (base " + j + ")");
break;
}
}

if (found)
break;
}

if (!found) {
System.out.println(a + " is not equal to " + b + " in any base 2..36");
}
}
}

public static void main(String args[])
{
Main problem = new Main();
problem.solve();
}
}

0 comments on commit a2f2777

Please sign in to comment.