The java solution is submitted by lixx2100 to contest.

- n is equal to x^(k-1) + x^(k-2) + ... + x + 1, where k is from 2 to, say, 66
- for each k from 2 to 66, we get "x", and the minimum of all "x"s is the answer
- To get "x", we use binary search approach with left = 2, and right = Long.MAX_VALUE
- to compare whether n is equal to x^(k-1) + x^(k-2) + ... + x + 1, we don't need to calculate x^(k-1) + x^(k-2) + ... + x + 1 from x.

if n = x^(k-1) + x^(k-2) + ... + x + 1, then n * (x - 1) = x^k -1.

in the source code, cb is x^k -1 and wb is n * (x - 1).

```
import java.math.*;
public class Solution {
public String smallestGoodBase(String n) {
BigInteger N = new BigInteger(n);
long base = Long.MAX_VALUE;
for (int k = 2; k < 66; k++) {
long l = 2, r = Long.MAX_VALUE - 5;
while (l <= r) {
long mid = l + (r - l) / 2;
BigInteger cb = BigInteger.valueOf(mid).pow(k).subtract(BigInteger.ONE);
BigInteger wb = N.multiply(BigInteger.valueOf(mid).subtract(BigInteger.ONE));
int cmp = cb.compareTo(wb);
if (cmp == 0) {
base = Math.min(base, mid);
break;
} else if (cmp < 0) {
l = mid + 1;
} else {
r = mid - 1;
}
}
}
return "" + base;
}
}
```