Challenge: Digit Fifth Powers

Posted on: August 23, 2017 11:28:58 PM

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44

As 1 = 14 is not a sum it is not included.

The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

This is another relatively straight forward challenge where a modified brute force approach is fastest. I cached the 0-9 fifth powers so they wouldn't always need to be calculated and based on those results, it was clear that a good starting point was 35 since there was no possible way it could be anything between 25 and 35. The next step is finding an upper bound. I started by taking 5x95 and found that the result contained 6 digits. So I put the upper bound to 6x96 to support the 6 digits. The rest is just letting it loop and finding if the on going sum is larger than the initial number.
using System;
using System.Diagnostics;

namespace Project_Euler_30
    internal class Program
        // 5x9^5 has 6 digits, so the upper bound should be 6x9^6
        private const int UpperBound = 59049 * 6;

        private static readonly int[] powersCache = new int[] { 0, 1, 32, 243, 1024, 3125, 7776, 16807, 32768, 59049 };

        private static void Main(string[] args)
            Stopwatch sw = Stopwatch.StartNew();
            int result = 0;

            // start the loop at 243 since that is the lower bound (3^5) of a possible sum
            for(int i = powersCache[3]; i <= UpperBound; i++)
                int sum = 0;
                int workingNumber = i;

                while(workingNumber > 0)
                    int digit = workingNumber % 10;
                    workingNumber /= 10;

                    sum += powersCache[digit];

                    if(sum > i)
                        // passed the number, stop checking

                if(sum == i)
                    result += i;

            Console.WriteLine($"Sum of results: {result}");
            Console.WriteLine($"Took {sw.ElapsedMilliseconds}ms");


look at this

Lien December 16, 2021 7:41:39 AM

трейлер фильма человек паук нет пути домой Сколько Сцен После Титров Человек Паук Нет Пути Домой

Tristan August 27, 2022 3:42:36 AM

gay senior chat [url=""]gay page chat roulette[/url] miami downtown chat gay

GenniesrPa September 16, 2022 1:13:17 AM

free live gay webcam chat rooms [url=""]gay video chat apps ios[/url] gay masturbate chat

GenniesrPa September 16, 2022 3:41:16 AM

gay chat 877 *** 7000 [url=""]gay teen cam chat[/url] zoom chat rooms gay chat

GenniesrPa September 16, 2022 6:31:27 AM

my essay writer [url=""]cheap essay online[/url] buy essay cheap online

MarrissrPa September 20, 2022 12:22:22 AM

essay writing helper [url=""]cheap essay online[/url] the best custom essay writing service

MarrissrPa September 20, 2022 12:25:55 AM

help with essay [url=""]academic essay writing services[/url] buying essays online

MarrissrPa September 20, 2022 1:08:16 AM

essay writers for pay [url=""]scholarship essay writing help[/url] essay writer

DorolisasrPa September 20, 2022 7:35:47 PM

admission essay editing service [url=""]college essay help[/url] best admission essay editing service

DorolisasrPa September 20, 2022 7:39:43 PM

best essay help review [url=""]do essay writing services work[/url] best essay writing company

DorolisasrPa September 20, 2022 8:19:56 PM

essay writer cheap [url=""]buy an essay cheap[/url] custom essay writing help

MartysrPa September 21, 2022 5:55:46 PM

help in writing essay [url=""]cheap essays[/url] the essay writer

MartysrPa September 21, 2022 5:59:27 PM

help writing a comparison and contrast essay [url=""]legitimate essay writing services[/url] cheap essay online

MartysrPa September 21, 2022 6:40:23 PM

where to buy essays [url=""]essay help websites[/url] write my college essay me

MerolasrPa September 22, 2022 1:51:06 PM

custom application essay [url=""]essay writer helper[/url] best website for essays

MerolasrPa September 22, 2022 1:55:25 PM

service essay [url=""]can someone write my essay[/url] custom essay station

MerolasrPa September 22, 2022 2:42:08 PM

mba essay writing services [url=""]best college essay editing service[/url] best online essay writer

AshlensrPa September 23, 2022 9:38:21 AM

buy custom essay [url=""]cheap essay services[/url] essay service

AshlensrPa September 23, 2022 9:42:18 AM

custom essays service [url=""]help writing a essay[/url] best essay service

AshlensrPa September 23, 2022 10:26:15 AM

essay writing on customer service [url=""]essay writing service usa[/url] write my essay review

CharitasrPa September 24, 2022 11:17:10 PM

romeo and juliet essay help [url=""]best custom essay writing service[/url] essay writing service best

CharitasrPa September 24, 2022 11:20:06 PM

top essay writing services [url=""]pay for essay cheap[/url] essay custom writing

CharitasrPa September 25, 2022 12:00:40 AM

higher english critical essay help [url=""]custom essay service toronto[/url] who will write my essay for me

NanicesrPa September 25, 2022 6:15:01 PM

application essay help [url=""]essay writer service review[/url] essay checking service

NanicesrPa September 25, 2022 6:18:21 PM

service essays [url=""]college essay help service[/url] medical school essay writing service

NanicesrPa September 25, 2022 7:00:29 PM

essay paper writing help [url=""]college essay help nyc[/url] reviews of essay writing services

ChelsaesrPa September 26, 2022 1:55:31 PM

english essay writers [url=""]best custom essay website[/url] help essays

ChelsaesrPa September 26, 2022 2:40:02 PM

custom essay paper writing [url=""]write my essay for money[/url] help me essay

PennysrPa September 27, 2022 9:02:10 AM

college admissions essay help [url=""]college essay writers block[/url] cheap essay writers

PennysrPa September 27, 2022 9:06:53 AM

help with writing essays [url=""]what is the best custom essay writing service[/url] essay writers online

PennysrPa September 27, 2022 9:50:29 AM

best essay website [url=""]cheap essay writing service usa[/url] custom essay services

TammiesrPa September 28, 2022 4:55:31 AM

help writing a college essay [url=""]essay help 123[/url] essay writer website

TammiesrPa September 28, 2022 5:36:32 AM

professional custom essays [url=""]essay writing service cheap[/url] where to buy essays

AntoniesrPa September 29, 2022 12:55:09 AM

can someone write my essay [url=""]buy essay online cheap[/url] essay writing service us

AntoniesrPa September 29, 2022 1:34:57 AM

how to write my essay [url=""]custom essay help[/url] college essay editing services

RhiamonsrPa September 29, 2022 8:29:54 PM

write my history essay [url=""]help with my essay[/url] best essay help review

RhiamonsrPa September 29, 2022 8:33:55 PM

professional essay writers review [url=""]essay custom writing[/url] top ten essay writing services

RhiamonsrPa September 29, 2022 9:11:47 PM

essay writing assignment help [url=""]essay writing help[/url] buy essay writing online

CharosrPa September 30, 2022 3:26:23 PM

buy essay paper [url=""]essay correction service[/url] online essay writers

CharosrPa September 30, 2022 4:02:54 PM

higher english critical essay help [url=""]professional college essay writers[/url] buy college essays

DronasrPa October 1, 2022 9:56:59 AM

assignment essay help [url=""]essay writers online[/url] help with argumentative essay

DronasrPa October 1, 2022 10:01:19 AM

essay writing service ratings [url=""]cheapest essay writing service[/url] critical essay help

DronasrPa October 1, 2022 10:43:57 AM

buy essay [url=""]essays services[/url] top 10 essay writing services

TwylasrPa October 2, 2022 5:28:19 AM

top essay writing websites [url=""]buy custom essay[/url] who will write my essay for me

TwylasrPa October 2, 2022 6:12:20 AM

best essays writing service [url=""]best essay writer[/url] best essay writing service

LeilahsrPa October 3, 2022 2:13:19 AM

customer service essays [url=""]custom essay writing cheap[/url] what is the best custom essay site

LeilahsrPa October 3, 2022 2:17:01 AM

essays writing service [url=""]custom essay writing service[/url] help with my essay

LeilahsrPa October 3, 2022 2:58:02 AM

best custom essay website [url=""]help writing a college essay[/url] custom essays essay help

CthrinesrPa October 4, 2022 12:08:14 AM

essay help 123 [url=""]help with writing a essay[/url] best essay writing websites

CthrinesrPa October 4, 2022 12:12:11 AM

essay on service to humanity [url=""]write my essay review[/url] hire essay writer

CthrinesrPa October 4, 2022 12:50:38 AM

cheap custom essay [url=""]college essay help nyc[/url] help writing a argumentative essay

GinniesrPa October 9, 2022 12:05:04 PM

college application essay writers [url=""]online essay writer[/url] uc essay help

GinniesrPa October 9, 2022 12:45:06 PM

essay writting service [url=""]buy college essay[/url] admission college essay help

VivienesrPa October 11, 2022 6:25:29 PM

essay writing help online [url=""]essay writing on customer service[/url] online essay services

VivienesrPa October 11, 2022 7:03:15 PM

help 123 essay [url=""]college application essay editing services[/url] graduate school essay writing service

EastersrPa October 13, 2022 9:24:53 AM

help on essay writing [url=""]essay homework help[/url] write my essay south park

EastersrPa October 13, 2022 10:08:00 AM

QhcUCDC October 30, 2022 5:54:05 PM

QiaMHXS October 31, 2022 11:31:23 AM

custom essay online [url=""]essay help live chat[/url] essaywriting service

DorolisasrPa November 19, 2022 7:15:31 AM

write my essay for me no plagiarism [url=""]essay writers cheap[/url] buy cheap essays

MartysrPa November 20, 2022 1:02:06 PM

online essay writer [url=""]pay for essay cheap[/url] instant essay writer

MartysrPa November 20, 2022 1:06:52 PM

online custom essays [url=""]college admission essay editing services[/url] online essay editing service

MartysrPa November 20, 2022 2:05:33 PM

buy essays online reviews [url=""]academic essay service[/url] i need help writing a essay

MerolasrPa November 21, 2022 8:51:07 PM

help me with my essay [url=""]using essay writing service[/url] help writing my college essay

MerolasrPa November 21, 2022 8:56:28 PM

college application essay service [url=""]common app essay help[/url] professional essay writers for hire

MerolasrPa November 21, 2022 9:52:26 PM

help with writing college essays [url=""]essay writing company reviews[/url] service to others essay

AshlensrPa November 23, 2022 5:44:52 AM

help me do my essay [url=""]who can i pay to write my essay[/url] need help with essay writing

AshlensrPa November 23, 2022 5:50:03 AM

custom essay station [url=""]definition essay help[/url] help with essay papers

CharitasrPa November 24, 2022 1:25:06 PM

where to buy essays [url=""]essay on help[/url] custom essay writing reviews

CharitasrPa November 24, 2022 1:30:21 PM

personal essay help [url=""]pay to write my essay[/url] cheap essay

CharitasrPa November 24, 2022 2:27:59 PM

custom my essay [url=""]custome essay[/url] nursing essay help

NanicesrPa November 25, 2022 10:47:39 PM

i need help writing a descriptive essay [url=""]essays writing help[/url] scholarship essay writing service

NanicesrPa November 25, 2022 11:50:20 PM

cheap essays online [url=""]english literature essay help[/url] application essay writing service

ChelsaesrPa November 27, 2022 7:59:51 AM

essay writing company reviews [url=""]write my social work essay[/url] buying essays online

ChelsaesrPa November 27, 2022 9:14:59 AM

best essay help review [url=""]custom law essays[/url] write my essay custom writing

PennysrPa November 28, 2022 5:12:00 PM

good essay writing service [url=""]write custom essays[/url] buy essays cheap

PennysrPa November 28, 2022 5:18:21 PM

english literature essay help [url=""]essay help pros[/url] top custom essay services

PennysrPa November 28, 2022 6:24:28 PM

Leave a Comment