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. (转)apache的keepalive和keepalivetimeout(apache优化)

    KeepAlive指的是保持连接活跃,类似于Mysql的永久连接.   如果将KeepAlive设置为On,那么来自同一客户端的请求就不需要再一次连接,避免每次请求都要新建一个连接而加重服务器的负担. ...

  2. 分享:Svg文件转换为图片(调用 Inkscape 命令行)

    其实只是做了简单封装,可以方便进行批量转换. 获取Svg对象坐标的代码请看:根据svg节点对象类型和路径值转换坐标值, DrawingColor方法是进行颜色填充的. /// <summary& ...

  3. 带参数的查询防止SQL注入攻击

    把单引号替换成两个单引号,虽然能起到一定的防止SQL注入攻击的作用,但是更为有效的办法是把要拼接的内容做成“参数” SQLCommand支持带参数的查询,也就是说,可以在查询语句中指定参数: 参数的设 ...

  4. Android学习笔记(SQLite的简单使用)

    1.SQLite介绍 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中.它是D.RichardHipp建立的公有领域项目.它的设计目标是嵌入式的,而且 ...

  5. BearSkill实用方法之UITextField限制输入的字符数量

    原文:http://blog.csdn.net/xiongbaoxr/article/details/51525061      

  6. Objective-C发展历史

    Objective-C发展历史 苹果图标由来: 被咬了一口苹果的LOGO是为了纪念计算机科学的创始人阿兰· 麦席森· 图灵.当年图灵由于身为同性恋者,被强行 "治疗",在被迫注射大 ...

  7. [转]toString()方法

    文章转自:http://blog.sina.com.cn/s/blog_85c1dc100101bxgg.html 今天看JS学习资料,看到一个toString()方法,在JS中,定义的所有对象都具有 ...

  8. POJ 2039 To and Fro(模拟)

    To and Fro Description Mo and Larry have devised a way of encrypting messages. They first decide sec ...

  9. Linux + C + Epoll实现高并发服务器(线程池 + 数据库连接池)(转)

    转自:http://blog.csdn.net/wuyuxing24/article/details/48758927 一, 背景 先说下我要实现的功能,server端一直在linux平台下面跑,当客 ...

  10. AS3.0面向对象的写法,类和实例

    package /*package是包路径,例如AS文件在ActionScript文件夹下,此时路径应为package ActionScript.必须有的.package中只能有一个class,在一个 ...