Self obsessed numbers

Consider a n n digit integer x = a n a n 1 a 1 x=\overline{a_na_{n-1}\cdots a_1} .

Let us call the number x x to be self obsessed if

x = a n a n 1 a 1 = a n a n + a n 1 a n 1 + + a 1 a 1 x=\overline{a_na_{n-1}\cdots a_1}=a_n^{a_n}+a_{n-1}^{a_{n-1}}+\cdots+a_1^{a_1} .

It is easy to see that the smallest such integer is x = 1 x=1 .

What is the next integer with this property?

HINT : 0 0 0^0 is . Hence, the answer cannot have zero as one of its digits.


The answer is 3435.

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.

6 solutions

Samarpit Swain
Aug 28, 2015

C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include<math.h>
using namespace std;

int main() {
unsigned long long int n=2,num,dig,sum;
 do
   {    num=n;
      sum=0;
  while(num>0)
{    dig=num%10;
         if(dig==0)
        break;
  sum+=pow(dig,dig);
    num/=10;
    }
  n++;
          }while(n!=sum)
    cout<<n<<endl;
return 0;
}

Output:

1
3435

Arulx Z
Aug 27, 2015
1
2
3
4
5
>>> count = 2
>>> while count != sum(int(x) ** int(x) for x in str(count)):
        count += 1
>>> print count
3435

Moderator note:

Simple standard approach.

3 3 + 4 4 + 3 3 + 5 5 = 27 + 256 + 27 + 3125 = 3435 3^3+4^4+3^3+5^5=27+256+27+3125=\boxed{3435}

Just a cool fact: these are called Münchhausen numbers! The next one, courtesy of OEIS, is 438579088.

Ryan Tamburrino - 6 years, 4 months ago

Log in to reply

That is assuming 0 0 = 0 0^0=0 if you read the hint in the question, it eliminates 438579088.

Janardhanan Sivaramakrishnan - 6 years, 4 months ago
David Holcer
Nov 7, 2015
1
2
3
4
5
6
7
8
9
c=2
while True:
   summ=0
   for i in str(c):
       summ+=(int(i)**int(i))
   if (summ==c):
       print c
       break
   c+=1

Simple enough approach, using string manipulation and breaking out of infinite loops.

Bill Bell
Oct 5, 2015

The hint is useful. You can also eliminate some wasted time by noting that there is no point in adding terms once the sum is at least as great as x x .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def isSelfObsessed(m):
    n=m
    r = 0
    while n:
        d=n%10
        if d==0:
            return False
        r=r+d**d
        if r>m:
            return False
        n=n/10
    return r==m

m=1
while True:
    m+=1
    result=isSelfObsessed(m)
    if result:
        print m
        break

Prakhar Gupta
Feb 3, 2015

Here is a J A V A JAVA code for this problem.

It must be a computer Science problem.

But solvable using the pencil & paper approach as well. I did it that way, so it's not a rigid cs problem.

Saya Suka - 1 year, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...