DFS
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6381 Accepted Submission(s): 3930
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 ......
我看见题目以为是深搜,吓死宝宝了,解释一下,9的阶乘=362880||*********||362880*7=一个7位数,就是3000000左右吧,362880*8=7位数还是3000000左右,所以3000000以后的就不需要考虑了,肯定没有,一个循环就解决了.
附代码:
#include<stdio.h>
#include<string.h>
int ac(int n)
{
int ans=1;
for(int i=1;i<=n;i++)
ans*=i;
return ans;
}
long i;
int main()
{
for(i=1;i<=40585;i++)
{
long m=0,n=i;
while(n)
{
int ans=n%10;
m+=ac(ans);
n/=10;
}
if(m==i)
printf("%d\n",i);
}
return 0;
}