Solution to ACM problem; good practice with base conversion and BigInteger class