Problem Description
A DFS (digital factorial sum) number is found by summing the factorial of every digit of a positive integer.
For example, consider the positive integer 145 = 1!+4!+5!, so it ' s a DFS number.
Now you should find out all the DFS numbers in the range of int ([1, 2147483647]).
There is no input for this problem. Output all the DFS numbers in increasing order. The first 2 lines of the output is shown below.
Input
No input
Output
Output all the DFS number in increasing order.
Sample Output
1
2
......
In fact, you will know after output. The output is only 4 digits and you can output it directly.
Here, I wrote the process.
Public classmain{Static intFact[] =New int[Ten]; Public Static void Main(string[] args) {Dabiao ();//9!*7 7 digits-smaller than 9999999, not to mention the number behind, certainly small. for(intI=1; i<=9999999; i++) {if(IsTrue (i)) {System. out. println (i); } } }Private Static void Dabiao() {//factorial, note: the factorial of 0 is 1fact[0]=1; for(intI=1; i<fact.length;i++) {fact[i]=1; for(intj=1; j<=i;j++) {fact[i]=fact[i]*j; } } }//judgment is not equal Private StaticBooleanisTrue(inti) {if(i==1|| i==2){return true; }intsum=0;intN=i; while(n!=0){intk=n%Ten; SUM+=FACT[K]; n=n/Ten; }if(sum==i) {return true; }return false; }}
Hdoj (HDU) 2212 DFS (factorial related,)