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

……

分析:9的阶乘为362880, 9!*10 而且由0~9的阶乘组成的最大数就是3628800。

而且0的阶乘是1,而不是0.

因为根据阶乘定义 n!=n*(n-1)!;

1!=1*0!=1;

所以人为规定了0!=1;

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int k[10]= {1,1};
void ff()
{
int i;
for(i = 2; i < 10; i ++){
k[i] = k[i-1]*i;
// printf("%d\n",k[i]);
}
}
int main()
{
ff();
long i;
long a,sum;
for(i=1; i<=3628800; i++)
{
a=i;
sum=0;
while(a!=0)//a>0
{
sum+=k[a%10];
a=a/10;
//printf("%d\n",a);
}
if(sum==i)
printf("%ld\n",i);
}
return 0;
}

HDOJ 2212 DFS的更多相关文章

  1. HDOJ(HDU) 2212 DFS(阶乘相关、)

    Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...

  2. HDOJ 1312 DFS&BFS

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. HDOJ 1026 dfs路径保存

    #include<cstdio> #include<cstring> #include<cmath> ][]; #define inf 0xffffff int n ...

  4. HDOj 1010 DFS优化

    #include<cstdio> #include<cstring> ]={,,,-}; ]={,,-,}; ][]; int x1,y1,x2,y2; int step; i ...

  5. HDOJ 1427(dfs) 速算24点

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1427 思路分析: 题目要求判断是否存在一种运算组合使得4个数的计算结果为24,因为搜索的层次为3层,不 ...

  6. HDU 2212 DFS

    Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...

  7. DFS(dfs)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2212 DFS Time Limit: 5000/2000 MS (Java/Others)    Me ...

  8. DFS ZOJ 1002/HDOJ 1045 Fire Net

    题目传送门 /* 题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(X)相隔,问最多能放多少个炮台 搜索(DFS):数据小,4 * 4可以用DFS,从(0,0)开始出发,往(n-1,n-1 ...

  9. DFS HDOJ 2614 Beat

    题目传送门 /* 题意:处理完i问题后去处理j问题,要满足a[i][j] <= a[j][k],问最多能有多少问题可以解决 DFS简单题:以每次处理的问题作为过程(即行数),最多能解决n个问题, ...

随机推荐

  1. 评论一下现有几个开源IM框架(Msn/QQ/Fetion/Gtalk...)

    转载:http://www.cnblogs.com/zc22/archive/2010/05/30/1747300.html 前言 ---------------- 这阵子,在集成通讯框架, 由于不想 ...

  2. python基础知识三

    在考虑它们的运算时,一定要想到python是一门面向对象语言,它对类型的要求是不那么严格的,因为在完全面向对象的语言中,一切都是对象. 那么让我们重新 考虑+ -  *  /等操作,不再拘泥于传统的数 ...

  3. Jsp内置对象-session

    session内置对象介绍 个人理解:session因为是唯一的, session是与请求有关的会话期,它是java.servlet.http.HttpSession类的对象,用来表示和存储当前页面的 ...

  4. librarynotfoundforlPodsAFNetworking解决放案

    http://www.it165.net/pro/html/201503/36422.html

  5. 前端开发bower包管理器

    Bower 是 twitter 推出的一款包管理工具,基于nodejs的模块化思想,他可以很好的帮助你帮你解决js的依赖管理,比如jquery angular bootstrap 等等. 可以很方便的 ...

  6. Quartz定时任务使用小记(11月22日)

    骤然接触quartz,先从小处着手,why,what,how quartz定时任务: 为什么使用quartz定时任务,以及定时任务在实际应用场景下的特定需求. 1.用户方面的需要,为了提供更好的使用体 ...

  7. 解决WEB(apache)服务器time_wait过高的性能优化过程

    目录 1.网站的硬件环境 2.修改Httpd.conf 3.修改sysctl.conf文件 一.网站环境LAMP硬件环境 [root@www conf]# dmidecode -s processor ...

  8. 移动web页面使用微软雅黑字体的问题

    很多前端工程师在开发手机页面的时候,发现视觉设计师们喜欢用微软雅黑作为中文字体进行设计,于是写页面的时候也定义 font-family 为微软雅黑,后来发到线上后,细心的产品经理发现页面的字体不是微软 ...

  9. ajax请求遇到服务器重启或中断

    常会有不断轮询发送ajax请求,处理一些业务的场景. 要考虑到: 1. 服务器重启,中断,恢复后仍然能恢复正常业务处理. 服务器重启过程中,再次发送请求,请求状态将变为net::ERR_CONNECT ...

  10. bitVector@ java bit自我practice##Q&A:为何int 来初始化size of bitVector?long,甚至是BigInteger等策略

    /* * BitSets are packed into arrays of "words." Currently a word is * a long, which consis ...