Никола обнови решението на 29.10.2016 12:21 (преди над 1 година)
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("Let's see some example sqs - ssq values:")
+ for i := uint64(0); i <= 113; i++ {
+ fmt.Printf("Hello n=%v, your value is: %v\n", i, SquareSumDifference(i))
+ }
+}
+
+func SquareSumDifference(n uint64) uint64 {
+ ssq := sumSquares(n)
+ sqs := squareSum(n)
+ return sqs - ssq
+}
+
+func sumSquares(n uint64) (ssq uint64) {
+ // Go passes by value, so n is safe to mutate here.
+ for n > 0 {
+ ssq += n * n
+ n--
+ }
+ return
+}
+
+func squareSum(n uint64) uint64 {
+ return sumToN(n) * sumToN(n)
+}
+
+func sumToN(n uint64) (sum uint64) {
+ // Go passes by value, so n is safe to mutate here.
+ for n > 0 {
+ sum += n
+ n--
+ }
+ return
+}