`
to_zoe_yang
  • 浏览: 138874 次
  • 性别: Icon_minigender_2
  • 来自: 01
社区版块
存档分类
最新评论

Problem 34

 
阅读更多

问题描述:

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());
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics