Smallest Good Base

Problem Id: 483 Difficulty: Hard


Intuition

Solution


class Solution:
    def smallestGoodBase(self, n: str) -> str:
        n = int(n)
        max_m = int(math.log(n, 2))
        for m in range(max_m, 1, -1):
            k = int(n ** (1 / m))
            if n * (k - 1) == k ** (m + 1) - 1:
                return str(k)
        return str(n - 1)