Hdoj (HDU) 2212 DFS (factorial related,)

Source: Internet
Author: User

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,)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.