Leetcode 483 Solution

This article provides solution to leetcode question 483 (smallest-good-base)

https://leetcode.com/problems/smallest-good-base

Solution

class Solution(object):
    def smallestGoodBase(self, n):
        """
        :type n: str
        :rtype: str
        """
        n = int(n)
        for m in range(int(math.log(n, 2)), 0, -1):
            if m != 1:
                k = int(n ** (1.0 / m))
            else:
                k = n - 1;
            if sum(k ** i for i in range(m + 1)) == n:
                return str(k);
        return 0;