Николай обнови решението на 31.10.2016 21:19 (преди над 1 година)
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println(SquareSumDifference(10))
+}
+
+func pow(number, times uint64) uint64 {
+
+ if times == 0 {
+ return 1
+ }
+
+ var result uint64 = 1
+ var i uint64 = 0
+
+ for ; i < times; i++ {
+ result = result * number
+ }
+
+ return result
+}
+
+func SquareSumDifference(n uint64) uint64 {
+
+ var squareSumOfAll uint64 = 0
+ var squareSumSeparately uint64 = 0
+ var i uint64 = 1
+
+ for ; i <= n; i++ {
+ squareSumOfAll += i
+ squareSumSeparately += pow(i, 2)
+ }
+
+ squareSumOfAll = pow(squareSumOfAll, 2)
+
+ return squareSumOfAll - squareSumSeparately
+}