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

简介: 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;
    }
}
目录
相关文章
|
Java
hdu 1262 寻找素数对
hdu 1262 寻找素数对
45 0
八皇后(dfs全排列)
八皇后(dfs全排列)
98 0
|
定位技术 ice
POJ-3009,Curling 2.0(DFS)
POJ-3009,Curling 2.0(DFS)
|
定位技术 C++
HDU-1253,胜利大逃亡(DFS)
HDU-1253,胜利大逃亡(DFS)
洛谷P1331-海战(简单的DFS)
洛谷P1331-海战(简单的DFS)
|
机器学习/深度学习
POJ-1321,棋盘问题(DFS)
POJ-1321,棋盘问题(DFS)
|
机器学习/深度学习
HDU-2553,N皇后问题(DFS+回溯)
HDU-2553,N皇后问题(DFS+回溯)
HDU-1262,寻找素数对(素数打表)
HDU-1262,寻找素数对(素数打表)
黑白棋_lduoj_dfs深搜
Description Lagno是一种二人智力游戏。游戏设有一个黑方和一个白方。游戏桌面是正方形的,包含8行8列。 如果黑方玩家走出这样一步棋:将一枚黑子放在任一空格上,而在这个空格的八个方向(上、下、左、右和4个对角线方向)的至少一个方向上有一排白子被夹在这枚新下的黑子和其他黑子之间,任何方向,在新黑子和原来黑子之间的所有白子都要变成黑子。为这个游戏设计一个程序,计算一步棋中黑方能转变的白子数量的最大值。 Input 输入文件lango.in共8行,每行8个字符;“.”代表一个空格;“B”代表黑子,“W”代表白子
120 0