Sum of Fifth power of digits

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

1634 = 1 4 + 6 4 + 3 4 + 4 4 1634 = 1^{4} + 6^{4} + 3^{4} + 4^{4}

8208 = 8 4 + 2 4 + 0 4 + 8 4 8208 = 8^{4} + 2^{4} + 0^{4} + 8^{4}

9474 = 9 4 + 4 4 + 7 4 + 4 4 9474 = 9^{4} + 4^{4} + 7^{4} + 4^{4}

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

Find the sum of all the numbers (less than 1 million) that can be written as the sum of fifth powers of their digits.

Note: 1 5 = 1 1^5 = 1 is not considered a sum and it is not included.


Try other problems Here


The answer is 443839.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Kunal Gupta
Sep 19, 2017

Small Python Script :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def X(n):
  x = n
  val = 0
  while x>0:
    val+=(x%10)**5
    x/=10
  if val==n:
    return 1
  return 0
ans= 0
for i in range(2,1000000):
  if X(i)==1:
    ans+=i
print ans                                                            

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.lang.Math;

public class main {
    public static int last_digit(int n){
        n=n%10;
        return n;
    }

    public static void main(String[] args){
        int n,temp,temp_sum=0;
        for (int i=2;i<=9999999;i++) {
            n=i;
            temp=i;
            int sum=0;
            while (n > 0) {
                int temp_last = last_digit(n);
                int temp_power = (int) Math.pow(temp_last,5);
                n = (n - (last_digit(n))) / 10;
                sum += temp_power;
            }
            if(temp==sum){
                temp_sum+=temp;
                System.out.println("required number"+temp);
            }
        }
        System.out.println("Sum of Numbers = "+temp_sum);
    }
}

Steven Chase
May 31, 2017

Here's some primitive code (Python)

msum = 0

for j in range(1,10**6):

    num = j

    ####################################

    p6 = num / (10**6)

    num = num % (10**6)

    ####################################

    p5 = num / (10**5)

    num = num % (10**5)

    ####################################

    p4 = num / (10**4)

    num = num % (10**4)

    ####################################

    p3 = num / (10**3)

    num = num % (10**3)

    ####################################

    p2 = num / (10**2)

    num = num % (10**2)

    ####################################

    p1 = num / (10**1)

    num = num % (10**1)

    ####################################

    p0 = num / (10**0)

    num = num % (10**0)

    ####################################

    q = p6**5 + p5**5 + p4**5 + p3**5 + p2**5 + p1**5 + p0**5

    res = q - j

    if res == 0:

        msum = msum + j
        print j

print ""
print ""
print (msum - 1)


####### Results #######

1
4150
4151
54748
92727
93084
194979


443839

Type your code like this

"```python

Code

```"

Without Quotes, it will show numbers Too and looks beautiful.

BTW nice solution.

Rishabh Deep Singh - 4 years ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...