立方变自身--枚举

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;
    }
}
全部评论

相关推荐

酷酷的喜马拉雅山:感觉这比一直在初筛不动的好多了
点赞 评论 收藏
分享
面了100年面试不知...:头像换成柯南再试试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务