1 Star 0 Fork 0

catyMap/AlgorithmNote

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
smallestGoodBase.go 480 Bytes
一键复制 编辑 原始数据 按行查看 历史
dogemap 提交于 2021-06-21 08:19 +08:00 . 6-21更新
package main
import (
"fmt"
"math"
"math/bits"
"strconv"
)
func smallestGoodBase(n string) string {
nVal, _ := strconv.Atoi(n)
mMax := bits.Len(uint(nVal)) - 1
// k < n^(-s) < k + 1
for m := mMax ; m > 1 ; m -- {
k := int( math.Pow(float64(nVal), 1/float64(m)))
sum := 1
for i := 0 ; i < m ; i ++ {
sum = sum * k + 1
}
if sum == nVal {
return strconv.Itoa(k)
}
}
return strconv.Itoa(nVal - 1)
}
func main() {
fmt.Println(smallestGoodBase("13"))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助