1 Star 0 Fork 0

catyMap / AlgorithmNote

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
minimumPerimeter.go 439 Bytes
一键复制 编辑 原始数据 按行查看 历史
dogemap 提交于 2021-08-16 08:30 . 新增题库
package main
import (
"math"
"sort"
)
// r =1 , s = 12 , r = 2 , s = 12 + 24 = 36 , r = 3 , s = 12 + 24 + 36 = 72 , r = 4 , s = 12 + 24 + 36 + 48 = (a1 + an) * n / 2 = a1*(n+1)*n/2
func minimumPerimeter(neededApples int64) int64 {
maxNum := math.Sqrt(math.Sqrt(1e15 / 3))
return int64(sort.Search(int(maxNum), func(x int) bool {
num := 0
for x >= 1 {
num += 12 * x * x
x--
}
return num >= int(neededApples)
}) * 8)
}
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助