How many integers of $ m $ digits are equal to the sum of the $ m $ -th powers of their digits in the interval $[1, ..., 10 ^ 7]$?

63 Views Asked by At

I was checking the following number theory excercise:

The number $1634$ has an interesting property. This 4-digit number satisfies that the sum of the fourth powers of its digits gives the same number. That is, $1 ^ 4 + 6 ^ 4 + 3 ^ 4 + 4 ^ 4$ $=$ $1634$. How many integers of $ m $ digits are equal to the sum of the $ m $ -th powers of their digits in the interval $[1, ..., 10 ^ 7]$? What is the largest of those complies with said property in the same interval?

I've found using some research that the numbers under the power of four are:

$$1634 = 1^4 + 6^4 + 3^4 + 4^4$$ $$8208 = 8^4 + 2^4 + 0^4 + 8^4$$ $$9474 = 9^4 + 4^4 + 7^4 + 4^4$$

As $1 = 1^4$ is not a sum it is not included.

So my biggest number is $9474$ in this moment.

Is there a bigger number than that or other number that that meets the condition of the statement in the interval provided?

Any help will be really appreciated

1

There are 1 best solutions below

0
On BEST ANSWER

Use the following Java code:

public class Test {
    public static final long LIMIT = 10_000_000L;

    public static int len(long number) {
        return String.valueOf(number).length();
    }

    public static long pow(long number, int exp) {
        long prod = 1;
        for(int i = 0; i < exp; i++) {
            prod *= number;
        }
        return prod;
    }

    public static long sum(long number) {
        int m = len(number);
        long s = 0;
        while(number > 0) {
            long digit = number % 10;
            s += pow(digit, m);
            number /= 10;
        }
        return s;
    }

    public static void main(String[] args) {
        for(long num = 10; num < LIMIT; num++) {
            if(num == sum(num)) {
                System.out.println(num);
            }
        }
    } 
}

Output:

153
370
371
407
1634
8208
9474
54748
92727
93084
548834
1741725
4210818
9800817
9926315

Adjust LIMIT and you can proceed even further. Up to $10^9$:

24678050
24678051
88593477
146511208
472335975
534494836
912985153