HDu2212
2015-12-15 14:50
253 查看
DFS
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6792 Accepted Submission(s): 4180
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
......
方法一;
其实大多数的都是通过打表来实现的,这里我也讲一种!其实对付这种题目,最好的方法也就是打表!
附代码
附打表代码
方法二
其实方法二和方法一差不多,就是去求最大的一个数是多少!我从9999999开始的,然后就8888888…………往前面求,当我求到999999时我发现可以作为上界了;所以……
附代码
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6792 Accepted Submission(s): 4180
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
......
方法一;
其实大多数的都是通过打表来实现的,这里我也讲一种!其实对付这种题目,最好的方法也就是打表!
附代码
#include<stdio.h> int main() { printf("1\n2\n145\n40585\n"); return 0; }
附打表代码
#include<stdio.h> int main() { __int64 i,j,k,l,a[10],s; a[0]=1; for(i=1;i<=10;i++) a[i]=a[i-1]*i; for(i=1;i<=2147483647;i++) { k=i;s=0; while(k) { j=k%10; k=k/10; s=s+a[j]; } if(s==i) printf("%I64d\n",i); } return 0; }
方法二
其实方法二和方法一差不多,就是去求最大的一个数是多少!我从9999999开始的,然后就8888888…………往前面求,当我求到999999时我发现可以作为上界了;所以……
附代码
#include<stdio.h> int main() { __int64 i,j,k,l,a[10],s; a[0]=1; for(i=1;i<=10;i++) a[i]=a[i-1]*i; for(i=1;i<=999999;i++) { k=i;s=0; while(k) { j=k%10; k=k/10; s=s+a[j]; } if(s==i) printf("%I64d\n",i); } return 0; }
相关文章推荐
- 控制器
- 构建兼容浏览器的Angularjs web应用
- oracle的一些常规操作sql语句集
- 程序员 2015 年工作总结
- 旋转图像
- Forward-backward梯度求导(tensorflow word2vec实例)
- Category - 4
- AngularJS(03)---Http对象
- 负载均衡算法的简单介绍及实现!
- HTML5新增的主体结构元素
- iframe 自适应高度
- 很特别的一个动态规划入门教程
- 北京安徽企业商会第一届会长何帮喜同志讲话
- 新闻列表中标题和日期的左右分别对齐的几种处理方法
- woe和iv的含义
- 排序算法:堆排序
- 64位Win7安装Oracle12C临时位置权限错误解决方案
- 64位Win7安装Oracle12C临时位置权限错误解决方案
- Unity3D方法来隐藏和显示对象
- 当需要向数据库插入空值时,sql语句的判断