立方变自身--枚举

统计一个数的三次方得到的数后将各位加起来的到原来的数

package test;
public class main {
    public static void main(String[] args) {
        int x = 0;
        for(int i = 1 ; i < 1000000; i++) {         //三次方太过大了 采用暴力 不过要注意记得检验 要除去0
            if(is_true(i))
                x++;
        }
        System.out.println(x);
    }
    public static boolean is_true(int i ) {
        int sum = i*i*i;
        String str = sum + "";
        int count = 0 ;
        for(int x = 0 ; x < str.length() ; x++) {
            count += str.charAt(x)-'0';
        }
        if(count == i )
            return true;
        return false;
    }
}

猜你喜欢

转载自blog.51cto.com/14429166/2417018