Problem Description

A sixth entry in our  "Numeric  T-Shirt" line:  

Back of T-Shirt:  "The only integer equal to the sum of the 6th powers of its digits!"

Front:  __ __ __ __ __ __?

Background & Techniques

Another simple program for beginners.  The primary problem is how to pick the digits out of an integer and then compute the 6th power of each and add them up.   The trick to isolating the low order digit of a number is to compute the number mod 10.   The "mod" function returns remainders, and the remainder of dividing a number by 10 is the low order digit!.     Multiplying it by itself 5 times is good enough to compute the 6th power.   And finally, dividing the number by 10 truncates the low order digit moving  the next digit to the low order position so we can repeat the loop.  If we sum  these 6th powers inside the loop until all digits have been processed, we can check the sum against the original number and report those that  match. 

This implementation with 30 lines or so of code, takes the power as an input  value  so we can check values from 1 to 8  (above 8 the run times will get very long and numbers are approaching the limit of 32 bit integers). 

Running/Exploring the Program 

Suggestions for Further Explorations

Add a Stop button to allow user to interrupt execution for sl0ow computer or large values of N.  (Set Tag=1 on Stop button click.  In Search button click routine, set tag = 0 before loop and execute Application.processmessages and check for Tag=1 once in a while inside the loop.)
Time and display run times.
Try  using the IntPower function from Delphi's Math unit to calculate the powers.   Is it faster or slower than calculating the powers in a loop?
Use Int64 type, 64 bit integers, and find a way to check faster for numbers larger than 8 digits. 

 

Originally posted: May 5,  2003 Modified:November 07, 2008