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.
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 ......
题意是 求各位阶乘之和是否等于自己:
//拿到题的时候真的一脸茫然不懂 看这标题dfs 我自己就在哪里想怎么用广搜。。。。还是太蠢
//题目给的数据真是循环超时 啊
//最可笑的不是我不懂超时 而是我不懂。。。0!=??? 等于1啊笨蛋。
//循环上界2147483647是十位数 a[9]是6位数 哪怕10个九也是七位数。。所以上界设为10*a[9]
//写题 好像不百度就不会写哎 蠢哭了 要像比赛一样去做题
#include <stdio.h> int a[10]; int main() { int s=1; a[0]=1; for(int i=1;i<10;i++) { s*=i; a[i]=s; } int t,sum; for(int i=1;i<=10*a[9];i++) { t=i,sum=0; while(t) { sum+=a[t%10]; t/=10; } if(sum==i) printf("%d ",i); } return 0; }
第二次看题居然还是一点思路都没有 说明根本不理解啊。。。