徐稳权


私信TA

用户名:18671468805

访问量:9498

签 名:

等  级
排  名 557
经  验 4194
参赛次数 0
文章发表 58
年  龄 0
在职情况 学生
学  校 湖北生物科技职业学院
专  业

  自我简介:

解题思路:这个题呢,他在4150之前是没有五次方数,而到了194979之后的也没有五次方数,所以for的初始值和结束值,所有就用for循环,然后来分解for循环的i


注意事项: int类型四位数的分解是int a=i/1000;                               五位数的分解是 int a=i/10000;
                                                  int b=(i/100)%10;                                               int b=(i/1000)%10;

                                                  int c=(i/10)%10;                                                  int c=(i/100)%10;                                                                                                            int d=i%10;                                                         int d=(i/10)%10;  
                                                                                                                              int e=i%10; 
                                                           
                                                
参考代码:

public class Text {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        for (int i = 4150; i <=194979; i++) {
            if (i>=4150&&i<10000) {
                int a=i/1000;
                int b=(i/100)%10;
                int c=(i/10)%10;
                int d=i%10;
                if (Math.pow(a, 5)+Math.pow(b, 5)+Math.pow(c, 5)+Math.pow(d, 5)==i) {
                    System.out.println(i);
                }
            }
            else if (i>=10000&&i<100000) {
                int a=i/10000;
                int b=(i/1000)%10;
                int c=(i/100)%10;
                int d=(i/10)%10;
                int e=i%10;
                if (Math.pow(a, 5)+Math.pow(b, 5)+Math.pow(c, 5)+Math.pow(d, 5)+Math.pow(e, 5)==i) {
                    System.out.println(i);
                }
            }
            else {
                int a=i/100000;
                int b=(i/10000)%10;
                int c=(i/1000)%10;
                int d=(i/100)%10;
                int e=(i/10)%10;
                int f=i%10;
                if (Math.pow(a, 5)+Math.pow(b, 5)+Math.pow(c, 5)+Math.pow(d, 5)+Math.pow(e, 5)+Math.pow(f, 5)==i) {
                    System.out.println(i);
                }
                
            }
        }

    }

}


 

0.0分

2 人评分

  评论区