0
点赞
收藏
分享

微信扫一扫

DFS

汤姆torn 2023-04-20 阅读 46


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


1 2 ......


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

举报

相关推荐

DFS(一)

dfs 模板

dfs入门

BFS/DFS

DFS题目

筑巢(dfs)

DFS应用

IDA*_DFS

【DFS】Sudoku

0 条评论