예제 #1
0
파일: c023.go 프로젝트: moul/euler
func C023() (interface{}, error) {
	upperLimit := 28123

	numbers := map[int]bool{}
	for i := 1; i < upperLimit; i++ {
		numbers[i] = true
	}

	abundantNumbers := []int{}
	for i := 2; i < upperLimit; i++ {
		divisors := utils.GetDivisors(i)
		sumDivisors := 0
		for _, divisor := range divisors[:len(divisors)-1] {
			sumDivisors += divisor
		}
		if sumDivisors > i {
			abundantNumbers = append(abundantNumbers, i)
		}
	}

	abundantNumbersLen := len(abundantNumbers)

	for i := 0; i < abundantNumbersLen; i++ {
		for j := i; j < abundantNumbersLen; j++ {
			abundantNumbersSum := abundantNumbers[i] + abundantNumbers[j]
			if _, found := numbers[abundantNumbersSum]; found {
				numbers[abundantNumbersSum] = false
			}
		}
	}

	sumNonAbundant := 0
	for number, isNotSum := range numbers {
		if isNotSum {
			sumNonAbundant += number
		}
	}

	return sumNonAbundant, nil
}
예제 #2
0
파일: c021.go 프로젝트: moul/euler
func c021_d(input int) int {
	divisors := utils.GetDivisors(input)
	return utils.SumIntSlice(divisors) - input
}