Curious Number

145 is a curious number, as 1 ! 1! + + 4 ! 4! + + 5 ! 5! = = 1 + 24 + 120 = 145 1 + 24 + 120 = 145 .

Find the sum of all numbers which are equal to the sum of the factorial of their digits that are less than 1 million.

Note: 1 ! = 1 1! = 1 and 2 ! = 2 2! = 2 are not considered sums and they are not included.


Try other problems Here


The answer is 40730.

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

 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
29
30
public class main {
    public static int last_digit(int n){
        n=n%10;
        return n;
    }
    public static int factorial(int n){
        if (n == 0)
            return 1;
        else
            return(n * factorial(n-1));
    }
    public static void main(String[] args){
        int n,Total_sum=0;
        for (int i=3;i<1_000_000;i++) {
            n=i;
            int sum=0;
            while (n > 0) {
                int temp_last = last_digit(n);
                int temp_fact = factorial(temp_last);
                n = (n - (last_digit(n))) / 10;
                sum += temp_fact;
            }
            if (sum == i) {
                Total_sum+=i;
                System.out.println("The Number " + i + " is a curious number.");
            }
        }
        System.out.println("The the of all Curious Numbers is : "+Total_sum);
    }
}

It never can be a solution because the solution must not be a script of java, c++, etc. \text { It never can be a solution because the solution must not be a script of java, c++, etc. }

. . - 3 months, 1 week ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...