立方变自身--枚举

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

相关推荐

AC鸽想进大厂:你是我见过最美的牛客女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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