问题描述:
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());
}
}
本文探讨了一种特殊的数学现象:存在一些整数等于其各位数字阶乘之和,并通过编程方式找出所有符合条件的整数,进而计算它们的总和。
1853

被折叠的 条评论
为什么被折叠?



