Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 49 additions and 0 deletions.
  1. +16 −0 go/problem20.go
  2. +33 −0 go/problem21.go
View
16 go/problem20.go
@@ -0,0 +1,16 @@
+package main
+
+import (
+ "fmt"
+ "math/big"
+)
+
+func main() {
+ n := new(big.Int)
+ n.MulRange(1, 100)
+ sum := 0
+ for _, d := range(n.String()) {
+ sum += int(d) - int('0')
+ }
+ fmt.Printf("%v\n", sum)
+}
View
33 go/problem21.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "fmt"
+ "math"
+)
+
+func divisor_sum(n int) int {
+ sum := 1 // all numbers are divisible by 1
+ nsqrt := int(math.Ceil(math.Sqrt(float64(n))))
+ for i := 2; i <= nsqrt; i++ {
+ if n % i == 0 {
+ sum += i
+ if i != nsqrt {
+ sum += n / i
+ }
+ }
+ }
+ return sum
+}
+
+const COUNT = 10000
+
+func main() {
+ total := 0
+ for i := 1; i < COUNT; i++ {
+ di := divisor_sum(i)
+ if di != i && i == divisor_sum(di) {
+ total += i
+ }
+ }
+ fmt.Printf("%v\n", total)
+}

No commit comments for this range

Something went wrong with that request. Please try again.