483. Smallest Good Base
一道數(shù)學(xué)題,證明在這里抒钱。https://discuss.leetcode.com/topic/76368/python-solution-with-detailed-mathematical-explanation-and-derivation
題意是如果一個(gè)數(shù)一直除以一個(gè)base翘魄,所得到的每個(gè)值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)