DFS

来源:互联网 发布:电脑软件无法安装 编辑:程序博客网 时间:2024/05/29 12:23

DFS

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6254    Accepted Submission(s): 3850


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 are shown below.
 

Input
no input
 

Output
Output all the DFS number in increasing order.
 

Sample Output
12......
C 语言程序代码
/*比较简单,理一下思路即可*/
#include<stdio.h>int f[10]={1,1},a[10];void dfs(){ int i; for(i=2;i<10;i++) {  f[i]=f[i-1]*i; }}int find(int n){ int sum=0,i,temp,m; m=n; while(n) {  temp=n%10;  sum+=f[temp];  n/=10; } if(m==sum)  return 1;  return 0;}int main(){ dfs(); int i; for(i=1;i<=47483;i++)//开太大虽也能算出结果,但超时,所以根据得出的结果将其范围缩小  if(find(i))  printf("%d\n",i);  return 0;}
0 0