Idea from doing some problems on brilliant.org

Look at this Pascal ( pseudocode ) program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    //This is a Pascal Pseudocode
    for i := 2 to 1000 do
    begin
        sum := 0;
        str(i,s);
        for j := 1 to length(s) do
        begin
            val(s[j],temp);
            inc(sum,temp*temp*temp)
        end;
        val(s,temp);
        if (sum = temp) then
            writeln(temp)
    end;

Above is a Pseudocode of a program.
What is the sum of all the output of the temp variable ?


The answer is 1301.

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.

1 solution

Jansen Wu
Mar 19, 2015

Actually, you will get Narcissistic Numbers sequence with range [2,1000] .
So this is all the Narcisstic Numbers :

153 = 1 3 + 5 3 + 3 3 153 = 1^{3} + 5^{3} + 3^{3} 370 = 3 3 + 7 3 + 0 3 370 = 3^{3} + 7^{3} + 0^{3} 371 = 3 3 + 7 3 + 1 3 371 = 3^{3} + 7^{3} + 1^{3} 407 = 4 3 + 0 3 + 7 3 407 = 4^{3} + 0^{3} + 7^{3}

So the sum of all the output is 153 + 370 + 371 + 407 = 1301 153 + 370 + 371 + 407 = 1301 Hence, the result is 1301

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...