Search code examples
javabignum

How to fix "largeNumber^5+1 = largeNumber^5" in Java


I am searching for a, b, and c such that a^5+b^5 = c^5. My program yields 2000^5+1= 2000^5. Why is this happening and how to fix it?

public class Euler {

     public static void main(String[] args) {
        long i=0;
        int power = 5;
        int a1 = 1; 
        int a2 = 2000;

        boolean isSolved = false;
        long sumOfPowers = 0;
        double root = 0;
        long roundDown = 0;
        long roundDown2Power = 0;

            sumOfPowers = (long) (Math.pow(a1, power) + Math.pow(a2, power));
            root = Math.pow(sumOfPowers, 1.0/power);

            roundDown = (long) root;
            roundDown2Power = (long)Math.pow(roundDown, power);

            if (sumOfPowers == roundDown2Power) {
                isSolved = true;
                System.out.println(isSolved + " " + a1 + "^" + power + " + " + a2 + "^" + power + " + "  + "^" + power +  " = " + roundDown + "^" + power );
            }
        }
    }

I am searching for counterexamples of Euler's conjecture. I was successful for fifth power using this method An error searching for a counterexample to Euler's conjecture 27^5 + 84^5 + 110^5 + 133^5 = 144^5 (Lander & Parkin, 1966), it takes 6 seconds. I am trying to get 5800^4 + 217519^4 + 414560^4 = 422481^4 (Roger Frye, 1988), but when testing this module I find that my program yields 2000^5+1=2000^5. Which is a problem.


Solution

  • You should try to use BigInteger lib in Java.