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))
                {
                    abundantNumbers.Add(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)
                {
                    factors.Add(i);
                    factors.Add(num / i);
                }
            }

            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.

Comments


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

http://dzcpdemos.gamer-templates.de/dzcpv1554demo13/forum/?action=showthread&id=18&page=110 https://www.subristow.co.uk/blog/2018/02/09/the-meaning-of-illness/ http://myklibsystem.tk/index.php/fotogalereya/item/18/asInline https://heroplus.jp/nhuc-thung-dung-than-duoc-chon-phong-the/ http://fanstore.altervista.org/ https://a-strategy.ru/strategic-use-of-images-in-seo/ https://skinpureclean.ch/2021/03/20/bonjour-tout-le-monde/ http://motebu.s35.xrea.com/x/moteo/apeboard_plus.cgi https://zgong.ru/dzen-gun/ http://heinrich.no/ompagniet/gjestebok.php https://aligns.co.kr/mind-10/ http://prayermeetings.org/edwardsblog/author/administrator/ http://masodjie.com/ramadhan-dan-wakafa-billahi-syahida/ https://dokterryan.com/obat-aborsi-6-bulan.html http://beachandcity-life.com/trip-to-iceland/ https://fuzokushare.com/buzz/7841.html http://joelduncombe.com/jane-mark/ https://пунтаприма.рф/reservation/ https://www.theagiler.com/benefici-agile-marketing/ https://bodypass.net/nutrition/body-building-substances-legal/ http://officelyst.com/2020/01/14/comment-reussir-son-voyage-en-tanzanie/ https://members.tripod.com/wind_4/cgi-bin/fbbs.cgi https://blog.everivel.com/2020/06/27/rain-part-1/ https://emilyjerryfoundation.org/emilys-story/ http://minkscocoon.com/2019/11/no-1-chapter-4-gallbladder-7/ https://songperday.com/simple-plan-perfect/ https://naxostrailrace.gr/metagonistiko-deltio/ https://www.johnvandrumpt.nl/2018/09/18/hallo-wereld/ http://www.lesamisdevillepey.fr/villepey-sous-la-neige/p1020535/ https://dienmaysonganh.com/san-pham/may-cua-xich-tay-cut-katsu-2900.html http://juliesmith.design/2016/04/19/hello-world/ https://sitalpatinews.com/post/1147 https://www.trophy-hunter.net/2016/11/12/natgeo-quiz-wild-life-trophy-guide/ https://annecharlottederochechouartgraphiste.com/kraft http://www.kcarplaw.com/kenneth-carp/ https://livreblanc.beauvais-en-transition.info/index.php https://time.datko.ir/the-castle-on-the-cliff-majestic-magic-manoir/ https://world-economy-magazine.com/2019/10/22/cd-moon-light/ http://garagedoorrepaireulesstx.com/ https://www.babymam.tn/blog/le-dilemme-de-la-poussette/ http://yayainthecity.com/a-chal-taps-gunna-for-hollywood-love-watch-here/ http://tilegroutcleaningfriendswood.com/?review_posted=1 http://odeskthemes.com/product/gymfitness/ https://primer.com.ph/blog/2019/02/28/7-cleaning-services-in-the-metro/ https://cleaningexec.com/blog/top-boring-house-chores-in-your-home/ https://train2wininstitute.com/actuas-con-determinacion-2/ https://www.hvo-projects.com/hello-world http://w-area-default.torbara.com/2018/04/26/ https://en-us.podcaster.de/blog/seo-guide/comment-page-6884/ https://www.cerebral.com.sg/online-class-helen-ogrady-speech-drama/ http://www.sgserv.it/movarisch-2016/ http://www.yo.yoga/hola-mundo https://splco.me/tam/4355/ https://www.pricedeal.in/why-lisfinity-is-unrivaled-among-classifieds-themes/ https://helpikom.com/product/contrast-backpack/ http://nativepakistan.com/blogs/karachi-blog/ https://2xale.com/producto/planta-electrica-powermate/ http://bdp.fikp.umrah.ac.id/2018/05/30/buka-bersama-hmj-bdp-umrah/ https://peloporkrimsus.com/partai-solidaritas-indonesia-kalsel-peduli-banjir/ https://heartcare.gr/2019/03/09/imerida-gynaika-kai-athlitismos/ https://colemanhughes.org/my-open-letter-to-ibram-x-kendi-bonus/ https://www.ecoeediciones.com/2021/03/16/libro-impreso-vs-libro-digital/ http://astro.onlineprasad.com/astrology-expert/mahesh-maini/ https://anekanews.net/?direct=https://shopogolik-info.ru/jbl-t280-pro-tws/ http://tourbodies.com/beauty-beaches/all-aboard-the-rocky-mountaineer/ https://www.yuyiii.com/blog/goa-reopens/ https://talbottteas.com/4-unique-uses-for-tea/ https://kedc.ir/forum/showthread.php?mode=threaded&tid=3510&pid=4916 http://www.dsprobotics.com/support/viewtopic.php?f=6&p=215736 http://tanks.m-sk.ru/e107_plugins/forum/forum_post.php?rp.4008.104530 https://mugtama.com/more/science-and-technology/item/117080-2021-01-13-05-43-59.html?start=540 https://www.mam-sklad.pl/zapytanie-klienta.php/JBL-T280TWS-PRO-true-wireless-earphone-review-9016 http://refundfees.com/eldorado-6/comment-page-4907/ https://www.filmychai.com/members/admin/comments/voted/ https://oldachusa.com/shop/k-series/ http://patalloknews.com/2019/06/21/%E0%A4%95%E0%A4%B0%E0%A5%8B%E0%A4%A1%E0%A4%BC%E0%A5%8B%E0%A4%82-%E0%A4%95%E0%A5%80-%E0%A4%B6%E0%A4%BE%E0%A4%B8%E0%A4%95%E0%A5%80%E0%A4%AF-%E0%A4%9C%E0%A4%AE%E0%A5%80%E0%A4%A8-%E0%A4%B9%E0%A4%9C/ https://ankara-haber.com/istanbul-yonunde-trafik-durdu/ https://www.michaelkorsoutletcheapest.us.com/apartemen-dengan-suite-dijual-di-london-agustus-2021/ https://www.propergaanda.com/pakistan-open-squash-returns-to-the-country/ http://probki.vyatka.ru/content/reshenie-20112013-0?page=6 https://namayush.gov.in/content/whats-new-announcements?page=6568 https://www.techturnup.org/tools-of-online-learning/ http://topmedee.mn/i/237 https://thelegalit.com/kinds-of-punishments/ http://eventosmagazine.com/frecuentes/ninos-column/champagne-wishes/ https://newnormalwedding.envitation.cc/2021/09/15/stivekahhh/ https://www.menuiserie-fenetre.net/loire-atlantique-/15769/fay-de-bretagne/cp-44130/ http://www.kijkopkeramiek.nl/contact/ https://anushahiremath.com/tips-to-stay-motivated-during-depression/ https://bsssportingclub.com/blog_details.php https://www.goprint.pk/products/1183/proud-to-be-a-veterinarian http://pharmaciedujura.ch/component/k2/item/7?start=180 http://www.mrmatthews.ie/blog-post-layout-02 http://bbs.stupid4.org/image/old/im.cgi?page=41 https://yazaski.com/icinizi-isitacak-tavuk-suyu-corba-tarifi/ https://indigenouskokodaadventures.com/what-were-reading-part-3/ http://recursosanimador.com/scripts/librovisitas2.php?pagina=13 http://if.shantotto.com/puki/rep/index.cgi?lapse;show=616 https://www.dojobook.it/2019/06/come-funziona-il-bonus-cultura-da-500-euro.html

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

aberedgosofmkgfdskjf12324 microsoft office 2016 mac version history free downloadcall of cthulhu pc game downloadbilgisayar windows 7 ultimate yapma free downloadadaware download windows 10access remote pc free downloadmicrosoft office 2016 free filehippo free downloadmicrosoft word product key 2016 free downloadwindows 10 home single language 64 bit latest version download free downloadpixelmator free download for windows 7 free downloadmicrosoft office 2007 professional full version free download [url=https://bit.ly/3mjrnqD]Moto x lollipop update at038t.AT038T8217s Android Lollipop update for the Moto X has been suspended 8211 PhoneArena[/url] [url=https://bit.ly/3CPEqpz]Ati radeon xpress 1150 driver[/url] hp realtek audio driver windows 7 download 64 bit free scott herman leg workouts datacard sp25 plus driver monster galaxy zodiac islands samsung galaxy s8 manual download [url=https://bit.ly/37UdO8B]Asrock z370 killer sliac drivers.ASRock Z Killer SLIac[/url] [url=https://bit.ly/2WhfBCm]Directx 11 for house windows 10 download 64 bit.DirectX 11 Grab[/url] [url=https://bit.ly/3kcv3rs]Development log.Warlords Battlecry 3 Patches Updates Addons Downloads The Patches Scrolls[/url] ulead download free windows 8 free manual de microsoft publisher 2013 free download amazon corel pdf fusion free download apex legends download pc free adobe reader free download for windows xp sp2 32 bit free windows 10 media creation tool error 0xa001b free download download xampp for windows 7 x64 free download adobe audition cc portable 32 bit free download youtube app download for pc windows 8.1 download chinese font for windows xp free free [url=https://bit.ly/3D7iOFd]Labtec microphones. headset labtec[/url] [url=https://bit.ly/2W9eN27]Combat mission final blitzkrieg[/url] [url=https://bit.ly/3D4dRNn]Epson nx510 driver[/url] [url=https://bit.ly/3y9tyzu]The game will be available just in time for Christmas.Sega announces Football Manager Mobile for Android coming this November 8211 Android Authority[/url] [url=https://bit.ly/3CTIViO]Pantech um175 drivers[/url] [url=https://bit.ly/3ml9E1T]Geneforge 5 character editor[/url] punjabi typing master software free download full version for windows 7 t mobile tuesday apk ?????? ??????? don bradman cricket 17 crack revit manual pdf free download microsoft projects 2016 manual free downloadmicrosoft office outlook 2016 working offline free downloadmicrosoft official academic course microsoft project 2016 pdf free downloadmicrosoft snipping tool free download for windows 7 freeadobe reader free download for pc windows 10 64 bitinternet explorer 11 for windows xp sp3 free download freedownload voot app for pc windows xpcnet windows vista download freechrome keeps freezing windows 10 2019 free downloadwindows 10 pro keys buy free download [url=https://bit.ly/3ySs5OR]Windows 7 enterprise stuck logging off free download.Windows 7 gets stuck on the Logging Off screen[/url] [url=https://bit.ly/3y2T0q7]Universal serial bus controller driver windows 7 64 bit hp.Universal Serial Bus USB Controller Driver Download 8211 PC Matic Driver Library[/url] download guitar hero for pc windows 7 free gangstar vegas pc itunes the installer has insufficient privileges sense flip clock and weather not working mazda miata repair manual download vigo video app for pc update opengl windows 10 windows 8 copy software free download free gta 3 cheater apk free download utorrent not working on jio [url=https://bit.ly/3AXGOZM]Realtek 8821ae wireless lan 802.11ac pci-e nic driver.Microsoft improvement Catalog[/url] [url=https://bit.ly/3AYIxOu]Keep Your Computer Running at Peak Performance.Realtek wireless drivers for RTLE and Windows 7 32bit[/url] [url=https://bit.ly/3stwx4q]Expand castle build 2019.Powerleveling High LSI Monster Hunter build guide Castle Age Wiki Fandom[/url] [url=https://bit.ly/37QSPU6]Software y controladores para.HP EliteBook G3 Notebook PC HP Customer Support[/url] alkarno phone watch alchemistundelite plusdownload aplikasi burningjackbox party pack 3 apknovicorp wintoflash kuyhaa [url=https://bit.ly/2XCV5ww]Download snapchat for nokia lumia.Snapchat for Nokia XL Free download soft for Android smartphones[/url] [url=https://bit.ly/3jV0Eh6]Cloud-Based Endpoint Security.Native Wireless LAN Drivers 8211 Windows drivers Microsoft Docs[/url] reproductor windows media 12 download freedownload applock pro for androidheroes of the seven seas vrinpage 2007 free download for windows 7 freerome total war on windows 10 [url=https://bit.ly/2Wbp0vm]Wch.cn folder.Windows 10 and CH 8211 Installation 038 Troubleshooting 8211 Arduino Forum[/url] [url=https://bit.ly/3CVCQTc]Specification Ultimate edition.Windows 7 Ultimate ISO File Free Download 32 amp 64 Bit SoftGets[/url] how to make skyrim borderlessmicrosoft visual c++ 2010 service pack 1 redistributable package mfc security updatedownload aplikasi di itunesdownload smtp serverfree download adobe flash player terbaru full version [url=https://bit.ly/3z6dKhZ]Create an account on the HP Community to personalize your profile and ask a question.Download Driver Hp Pavilion Dv6 Beats Audio[/url] [url=https://bit.ly/3iTM8a7]Intel r 82583v gigabit network connection[/url] spss software free download for windows xp 32 bit freedownload flipboard for windows 7 freesri lakshmi ashtottara shatanamavaliharley davidson workshop manual free downloadmyanmar gospel songs mp3 free download [url=https://bit.ly/3fSVWzt]Join or Sign In.Adobe Flash Player Microsoft windows 10 Chrome CNET install[/url] [url=https://bit.ly/3k56EEe]Energizer usb charger.Energizer Power Products Energizer[/url] oxford dictionary english to marathi free downloadhow to download music on pspdownload itunes for windows vista 32 bit freege force 310mfree avi player windows 10 [url=https://bit.ly/3kbaLi5]Denon x600.Denon DN-X Two-Channel Digital Mixer is Now Available 8211 DJBooth[/url] [url=https://bit.ly/3ySfJ9K]Qualcomm completes acquisition of NUVIA..Download Qualcomm Atheros ARx Wireless Network Adapter Driver for Windows 10[/url] amd log utility drivervideo editor for mts filesduck capturesentio superbook review 2017framework 4.5 download https://bit.ly/3smkKF0 https://bit.ly/37PkV2h https://bit.ly/3snmttG https://bit.ly/2XxIHhb https://bit.ly/2XHZEpn https://bit.ly/3CSpgQt https://bit.ly/3maWYL7 https://bit.ly/2W2omAt https://bit.ly/3szR0EL https://bit.ly/3snQbP4 [url=https://ffridanilsson.blogg.se/2013/april/jobbas-litera.html]hindi to marathi dictionary free download[/url] [url=https://mesandra.blogg.se/2018/april/fredag.html]an vir task manager[/url] [url=https://myeshovslageri.blogg.se/2016/april/myes-hovslageri-smide.html]download other devices windows xp free[/url] [url=https://norske-casino.eu/book-of-ra-deluxe/comment-page-1/%5C%22https:/games-cv.com/book_of_ra_deluxe?refCode=wp_w527p123_cv777%5C]unduh filmora[/url] [url=https://iohlsson.blogg.se/2012/december/entry.html]genoil ethminer commands[/url] [url=https://matthewdascombe.com/index.php?submitted=597079]driver sound windows 8[/url] [url=https://packatochoklart.blogg.se/2015/march/borneo-2.html]tunatic[/url] [url=http://8thdays.co.kr/board/product/read.html?no=691354&board_no=4]windows installer for windows 7 64 bit ultimate free download free[/url] [url=http://gxc.pub/thread-131496-1-1.html]spintires free download full version[/url] [url=https://www.world-finance-conference.com/conference.php?id=22]download driver alfa network awus036h wireless usb adapter windows xp free[/url]

RobertSix September 19, 2021 12:51:31 PM

Leave a Comment