### Challenge: Non-abundant sums

Posted on: October 19, 2016 12:57:48 AM
This challenge wants you to find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. An abundant number is described as the sum of the proper divisors are greater than the original number. For example, 12 is the smallest abundant number with it's divisors 1, 2, 3, 4, 6 summed together being 16. Where 12 is the smallest abundant number, 24 is would be the smallest abundant sum.
Program.cs
```using Common.Math;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProjectEuler_23
{
internal class Program
{
private const int HighestNumNotAbundantSum = 28123;

private static bool IsAbundant(int i)
{
int[] factors = i.GetFactors().Distinct().ToArray();
int sum = factors.Sum() - i;

return sum > i;
}

private static void Main(string[] args)
{
int sum = 0;
bool[] isAbundantSum = new bool[HighestNumNotAbundantSum + 1];
List abundantNumbers = new List();

//12 is the lowest abundant number
for (int i = 12; i < HighestNumNotAbundantSum - 12; i++)
{
if (IsAbundant(i))
{

for (int x = 0; x < abundantNumbers.Count; x++)
{
int abundantSum = i + abundantNumbers[x];

if (abundantSum <= HighestNumNotAbundantSum)
{
isAbundantSum[abundantSum] = true;
}
}
}
}

for (int i = 1; i < isAbundantSum.Length; i++)
{
if (!isAbundantSum[i])
{
sum += i;
}
}

Console.WriteLine(\$"Sum of all numbers than can't be the sum of two abundant numbers: {sum}");
}
}
}
```
MathExtensions.cs
```using System.Collections.Generic;
using System.Linq;

namespace Common.Math
{
public static class MathExtensions
{
public static int[] GetFactors(this int num)
{
List factors = new List { 1, num };
int root = (int)System.Math.Sqrt(num);

for (int i = 2; i <= root; i++)
{
if (num % i == 0)
{
}
}

return factors.OrderBy(x => x).ToArray();
}
}
}
```
This code is pretty straight forward, first we loop starting at 12 since it's the lowest known abundant number up to the highest non-abundant number known subtract 12. Then we determine if the number is abundant and store it. To use as few loops as possible, we then calculate out all the possible sums and store those values into a BitArray. Last, we loop through the BitArray and sum all the false values to get the answer.
As a note: I've moved the generating of factors code into a common library that I'm going to start referencing in projects that require it because it is a pretty common math function needed for these. This will likely be the last time I post the code for it, if you're following my posts, you should have this function working for your future projects as well.

Happy New Year!!!

Christoper Booker January 11, 2021 1:48:36 PM

Useful piece

gamesellru May 16, 2021 11:37:39 AM

You actually make it seem so easy with your presentation but I find this topic to be actually something which I think I would never understand. It seems too complex and very broad for me. I'm looking forward for your next post, I will try to get the hang of it!

Larryamure July 22, 2021 12:30:06 PM

Hello everyone on this forum - thanks. My name is Mark and i am from luxembourg best regards :)

muudal August 4, 2021 11:32:54 PM

[b][url=https://nude.manhattan-massage.com/]nude massage midtown[/url][/b] Good day . Top craftsmen at the present time worth its weight in gold , in this regard prices for Thai massage in Manhattan Beach rather expensive . In our SPA you can find out all the beauty useful procedure practically for nothing . Relaxing massage of the whole body positive affects all without exception systems and organs our body: o Muscles and Joints - improved mobility , you will recover faster after a visual load, elimination of lactic acid and recovery from exercise o Skin - activates flow blood, occurs saturation oxygen o Vessels - getting rid of edema , normalizing the cardiovascular system and relieving anemia o Nervous system - improve mood , headaches go away , improve health, relief from headaches and spasms , relieve nervous tension and improve well-being . Swedish massage more important in case losing weight and getting rid of c ellulite. The Luxurious Classic massage in Ditmars waiting customer here. o Impressive variety options massage techniques o Sessions Hardware - vibration full body massage from 1 hour Offer all of you , visit the site and learn all methods of massage personally.

CraigRoara September 18, 2021 2:08:26 PM

удалите,пожалуйста! [url=https://russian-army-shop.cz/].[/url]

Evgenypwm September 18, 2021 10:36:37 PM

naturally like your web site however you have to test the spelling on quite a few of your posts. Many of them are rife with spelling issues and I find it very bothersome to tell the truth nevertheless I'll certainly come again again. mensv&auml;rk innan f&ouml;rsta mensen writhe.teswomango.com/map16.php

mensv&auml;rk innan f&ouml;rsta mensen September 19, 2021 1:16:49 AM

[url=https://dostup.net/teamviewer-dlya-android.html]https://dostup.net/teamviewer-dlya-android.html[/url]

Groverploni September 19, 2021 1:24:13 AM

[url=https://diakov.net/user/Groverrulty/]https://diakov.net/user/Groverrulty/[/url]

HenryDah September 19, 2021 2:31:12 AM

StivenGundes September 19, 2021 5:26:08 AM

удалите,пожалуйста! [url=https://russian-army-shop.cz/].[/url]

Evgenydbp September 19, 2021 10:02:44 AM

https://forums.asp.net/members/lilisone.aspx KW: Jezdzcy sprawiedliwosci Caly FILM Dailymotion FILM Jezdzcy sprawiedliwosci PL caÅ‚y film Jezdzcy sprawiedliwosci Caly FILM Cda Obejrzyj pelny FILM Jezdzcy sprawiedliwosci (2021) chomikuj

belleSiB September 19, 2021 10:35:09 AM

[url=https://anonymvpn.info]ключи[/url]

Jeffreyvef September 19, 2021 11:57:51 AM

RobertSix September 19, 2021 12:51:31 PM

Contact Me
Recent Blog Activity
Blog Archive