*"is a number that is the sum of its own digits each raised to the power of the number of digits"*. For example `8208` is an Armstrong number because 8208 = 8^4 + 2^4 + 0^4 + 8^4. We will say that `8208` is a

**level-4**A-number and call the power sum of its digits, an

**aSum**. Single digit numbers are obviously (level-1) Armstrong numbers , all the A-numbers up to level 4 are:

1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474There is a finite number of A-numbers, this is because the magnitude of a number grows quicker then it's aSum so that after certain point, the aSum falls behind. The largest A-number is a level-39ner.

This code calculates all A-numbers up to level-39 with the following timings *:

Level-15 0 sec. 41 numbers Level-18 2 sec. 46 numbers Level-20 6 sec. 51 numbers Level-21 11 sec. 53 numbers Level-22 15 sec 53 numbers Level-23 21 sec. 58 numbers Level-25 46 sec 66 numbers Level-39 3518 sec. (58 min) 88 numbers * i7-4790K CPU @ 4.00GHz

Please see my implementation: https://github.com/shamily/ArmstrongNumbers

ReplyDelete(Seems like for 88 BigIntegers it works faster ;) )