题解 | #尼科彻斯定理#
尼科彻斯定理
http://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85
package main
import (
"fmt"
"math"
"strconv"
)
//转化为数学问题,即等差数列求和问题,公差为2,由规律可知项数n等于输入的m
func VerifyingNicochaseTheorem(in int) string {
sum := math.Pow(float64(in), 3)
n := in
a1 := int(sum)/n - (n - 1)
var s string
s += strconv.Itoa(a1)
for i := 1; i < n; i++ {
a1 = a1+ 2
s += "+"
s += strconv.Itoa(a1)
}
return s
}
func main() {
var in int
fmt.Scanln(&in)
fmt.Println(VerifyingNicochaseTheorem(in))
}