問題描述:
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
解決問題:
public class Problem34 {
public static final int UP = 362880;
public static int jiecheng(int number){
int result = 1;
for(int i=2; i<=number; i++){
result *= i;
}
return result ;
}
public static int sum(){
int result = 0;
for(int i=11; i<UP; i++){
int value = 0;
int current = i;
while(current!=0){
value += jiecheng(current%10);
current = current/10;
}
if(value==i){
System.out.println(value);
result += value;
}
}
return result;
}
public static void main(String[] args){
System.out.println(sum());
}
}