-
Notifications
You must be signed in to change notification settings - Fork 0
/
p23.go
58 lines (45 loc) · 790 Bytes
/
p23.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"math"
"time"
)
func isAbundant(x int) bool {
sum := 1
for i := 2; i <= int(math.Sqrt(float64(x))); i++ {
if x%i == 0 {
sum += i
if x != i*i {
sum += x / i
}
}
}
return sum > x
}
func main() {
start := time.Now()
abundant := []int{12}
for i := 13; i < 28112; i++ {
if isAbundant(i) {
abundant = append(abundant, i)
}
}
check := make([]bool, 28124)
for i := 0; i < 28124; i++ {
check[i] = true
}
for i := 0; i < len(abundant); i++ {
for j := i; j < len(abundant) && abundant[i]+abundant[j] < 28124; j++ {
check[abundant[i]+abundant[j]] = false
}
}
sum := 0
for i, yes := range check {
if yes {
sum += i
}
}
fmt.Println(sum)
elapsed := time.Since(start)
fmt.Println("Elasped:", elapsed)
}