搜索Euler猜想的反例时出错 [英] An error searching for a counterexample to Euler's conjecture

查看:73
本文介绍了搜索Euler猜想的反例时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重复搜索有关Euler猜想的反例.我需要找到五个数字,例如a1^5+a2^5+3^5+a4^5 =a5^5.最小的反例是27 ^ 5 + 84 ^ 5 + 110 ^ 5 + 133 ^ 5 = 144 ^ 5.我想我正在遍历每个数字,并确保数字是有序的,但是,我没有得到预期的结果.请指出我的错误.

I am trying to repeat the search for a counterexample for Euler's conjecture. I need to find five numbers such that a1^5+a2^5+3^5+a4^5 =a5^5. The smallest counterexample is 27^5+84^5+110^5+133^5=144^5. I think I am looping over each number and make sure that the numbers are ordered, however, I don't get the expected result. Please point my error.

public class Euler {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int a1 = 1; //greatest
        int a2 = 1;
        int a3 = 1;
        int a4 = 1;  
        boolean solved = false;
        while (!solved) {
            if (a3 >= a4) { //major progress!!!
                System.out.println("values are " + a1 + " " + a2 + " " + a3 + " " + a4 + " " + solved);
                a4++;
                a3 = 1;
                a2 = 1;
                a1 = 1;
            }else if(a2 >= a3) {
                a3++;
                a2 = 1;
                a1 = 1;
            } else if(a1 >= a2) {
                a2++;
                a1 = 1;
            } 
            solved = antiEuler(a1, a2, a3, a4);//Check conjencture
            a1++;
        }    
    }    
    public static boolean antiEuler(int a1, int a2, int a3, int a4) {//

        double a5 = Math.pow(Math.sqrt(Math.pow(a1, 5) + Math.pow(a2, 5) + Math.pow(a3, 5) + Math.pow(a4, 5)), 0.2);
        double a6 = Math.floor(a5);
        if (a6 == a5) {
                        System.out.println("Done!");
            System.out.println(a1+" "+a2+" "+a3 +" "+a4+" "+a5);    


            return true;
        } else {
            return false;
        }
    }
}

推荐答案

此程序存在多个问题.

  • 首先,最小的示例包含144 5 ,该值大于6 * 10 10 ,因此int将不起作用.您应该使用长
  • 秒,您应该比较整数,而不是它们的根,以免遇到差错.该程序找到第一个示例.

  • first, the smallest example contains 1445 which is greater than 6*1010, so int will not work. You should use long
  • second, you should compare integers, not their roots to avoid running into a near miss. This program finds the first example.

public class Euler {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    long a1 = 1; //smallest 
    long a2 = 1;
    long a3 = 1;
    long a4 = 1;  //greatest
    boolean isSolved = false;
    double a6 = 0;
    double a7 = 0;
    long a8 = 0;
    double a9 = 0;
    while (!isSolved) {
        a1++;
        if (a1 > a2) {
            a2++;
            a1 = 1;
        }
        if (a2 > a3) {
            a3++;
            a2 = 1;
            a1 = 1;
        }
        if (a3 > a4) { 
            //System.out.println(a4 + " " + isSolved);
            a4++;
            a3 = 1;
            a2 = 1;
            a1 = 1;
        }
        a6 = Math.pow(a1, 5) + Math.pow(a2, 5) + Math.pow(a3, 5) + Math.pow(a4, 5);
        a7 = Math.pow(a6, 0.2);

        a8 = (long) a7;
        a9 = Math.pow(a8, 5);

        if (a6 == a9) {
            isSolved = true;
            System.out.println(a1 + " " + a2 + " " + a3 + " " + a4 + " " + a8);
        }           
    }
}
}

这篇关于搜索Euler猜想的反例时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆