HDOJ(HDU) 2212 DFS(阶乘相关、)
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
……
其实你输出后就会知道。。输出就只有4个数,你可以直接输出。
在这里,我是写了过程的。
public class Main{
static int fact[] = new int[10];
public static void main(String[] args) {
dabiao();
//9!*7 7位数-比9999999小,后面的数字更不用说了,肯定小。
for(int i=1;i<=9999999;i++){
if(isTrue(i)){
System.out.println(i);
}
}
}
private static void dabiao() {
//求阶乘的,注意:0的阶乘为1
fact[0]=1;
for(int i=1;i<fact.length;i++){
fact[i]=1;
for(int j=1;j<=i;j++){
fact[i]=fact[i]*j;
}
}
}
//判断是不是相等
private static boolean isTrue(int i) {
if(i==1||i==2){
return true;
}
int sum=0;
int n=i;
while(n!=0){
int k=n%10;
sum+=fact[k];
n=n/10;
}
if(sum==i){
return true;
}
return false;
}
}
HDOJ(HDU) 2212 DFS(阶乘相关、)的更多相关文章
- HDU 2212 DFS
Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...
- HDOJ(HDU).2660 Accepted Necklace (DFS)
HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...
- HDOJ(HDU).2266 How Many Equations Can You Find (DFS)
HDOJ(HDU).2266 How Many Equations Can You Find (DFS) [从零开始DFS(9)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零 ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- HDOJ(HDU).1258 Sum It Up (DFS)
HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDOJ(HDU).1035 Robot Motion (DFS)
HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...
- HDOJ(HDU).1016 Prime Ring Problem (DFS)
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDOJ(HDU).1015 Safecracker (DFS)
HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...
随机推荐
- ASP.NET MVC 第四回 向View传值
一.ViewData与TempData属性来向View页传递对象 上文中已经提到,使用ViewData可以将数据由Controller传递到View 在前文中我们建立了EiceController类 ...
- 实现多个ContentProvider对多张表进行操作
http://blog.csdn.net/maylian7700/article/details/7365373 SQLite数据库直接操作类: DatabaseHelper.java package ...
- iOS socket编程
// // ViewController.m // socket // // Created by emerys on 16/3/2. // Copyright © 2016年 Emerys. All ...
- css media
/* media */ /* 横屏 */ @media screen and (orientation:landscape){ } /* 竖屏 */ @media screen and (orient ...
- java_设计模式_单例模式_Singleton Pattern(2016-08-04)
概念: 单例模式确保某个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 适用场景: 在计算机系统中,线程池.缓存.日志对象.对话框.打印机.显卡的驱动程序对象常被设计成单例.这些应用都或多或 ...
- 理解pkg-config工具
你在 Unix 或 Linux 下开发过软件吗?写完一个程序,编译运行完全正常,在你本机上工作得好好的,你放到源代码管理系统中.然后,告诉你的同事说,你可以取下来用了.这时,你长长的出了一口气,几天的 ...
- SGU 155.Cartesian Tree
时间限制:0.25s 空间限制:6M 题意: 给出n(n< 50000)个含双关键字(key,val)的节点,构造一颗树使该树,按key值是一颗二分查找树,按val值是一个小根堆. Soluti ...
- UILongPressGestureRecognizer的selector多次调用解决方法
当你使用longPress gesture recognizer 时,你可能会发现调用了多次. UILongPressGestureRecognizer *longPress = [[UILongPr ...
- JQuery 点击控件获取当前坐标时不兼容IE7
现在要求在点击文本框时,获取文本框的坐标,需要相对文本框的位置来显示信息. 思路就是,绑定文本框的click 事件,一旦有点击就触发,去调用clickevent 函数执行计算. $('#txt_m') ...
- SQL Server Analysis Services 数据挖掘(1)
来源: http://technet.microsoft.com/zh-cn/library/dn633476.aspx 假如你有一个购物类的网站,那么你如何给你的客户来推荐产品呢?这个功能在很多 电 ...