博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ 2212 DFS
阅读量:7127 次
发布时间:2019-06-28

本文共 1112 字,大约阅读时间需要 3 分钟。

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 
#include
#include
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;}

转载地址:http://zjoel.baihongyu.com/

你可能感兴趣的文章
Linux系统命令Cut使用
查看>>
我的友情链接
查看>>
MySQL 游标(cursor)简单应用
查看>>
10个让朋友对你刮目相看的CoffeeScript单行代码绝技
查看>>
我的友情链接
查看>>
hadoop与spark集成开发环境
查看>>
[置顶] 关于jquery某一元素重复绑定的问题
查看>>
Android Camera2 拍照速度过慢问题
查看>>
摄像头远程监控的Vb.net实现方法(转)
查看>>
ubuntu安装nodejs
查看>>
【Web探索之旅】第一部分:什么是Web?
查看>>
man用来显示中文cman
查看>>
加快app store下载速度【网上看到的】
查看>>
Spring4.1-Application Event
查看>>
Python内置模块(一)
查看>>
利用最新新浪微博API做到桌面程序
查看>>
TRUNC函数的用法
查看>>
gre
查看>>
灵巧还是笨重?利用Textarea从浏览器复制字符到剪贴板
查看>>
CentOS 7.4利用Iptables开启远程访问
查看>>