-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb23.go
57 lines (50 loc) · 985 Bytes
/
pb23.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
package main
import (
"fmt"
)
func divisors(num int) []int{
numbers := []int{}
for i:=1;i<num;i++{
if num%i==0{
numbers = append(numbers, i)
}
}
return numbers
}
func sum(arr []int) int{
s := 0
for _,val := range arr {
s += val
}
return s
}
func main(){
// Calculate all abundant numbers
limit := 28123
abundants := []int{}
for i:=1;i<=limit;i++{
divs := divisors(i)
if sum(divs) > i{
abundants = append(abundants, i)
}
}
// Find all possible sums of abundant numbers
canBeWrittenAsAbundant := make(map[int]bool)
for i:=0;i<len(abundants);i++{
for j:=i;j<len(abundants);j++{
s := abundants[i] + abundants[j]
if s <= limit{
canBeWrittenAsAbundant[s] = true
}
}
}
// Find the sum of those numbers not possible to
// write as an abundant number
ca_sum := 0
for k:=1;k<=limit;k++{
if !canBeWrittenAsAbundant[k]{
ca_sum += k
}
}
fmt.Println(ca_sum)
}