483. Smallest Good Base
一道数学题,证明在这里。https://discuss.leetcode.com/topic/76368/python-solution-with-detailed-mathematical-explanation-and-derivation
题意是如果一个数一直除以一个base,所得到的每个值mod base都是等于1
class Solution(object):
def smallestGoodBase(self, n):
"""
:type n: str
:rtype: str
"""
n = int(n)
max_m = int(math.log(n,2)) # Refer [7]
for m in range(max_m,1,-1):
k = int(n**m**-1) # Refer [6]
if (k**(m+1)-1)//(k-1) == n:
# Refer [3]
return str(k)
return str(n-1)