waltermilner

Untitled

Jul 15th, 2018
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1.  
  2. import java.util.Arrays;
  3.  
  4. public class Test { // Euler's conjecture
  5.   // Lander and Parkin's counter example for n=5
  6.  
  7.   static final int RANGE = 400; // all fifth power of up to 400
  8.   static long[] fifths = new long[RANGE]; // array to hold them
  9.  
  10.   static void makeFifths() { // fill array
  11.     for (long i = 0; i < RANGE; i++) {
  12.       fifths[(int) i] = i * i * i * i * i;
  13.     }
  14.   }
  15.  
  16.   static boolean perfectFifth(long n) { // is n a perfect fifth power?
  17.   // look in the array
  18.     return (Arrays.binarySearch(fifths, n) > 0);
  19.  
  20.   }
  21.  
  22.   public static void main(String args[]) {
  23.     makeFifths();
  24.  
  25.     for (long m = 1; m < RANGE; m++) {
  26.       for (long n = m; n < RANGE; n++) {
  27.         for (long p = n; p < RANGE; p++) {
  28.           for (long q = p; q < RANGE; q++) {
  29.             long result = m * m * m * m * m + n * n * n * n * n + p * p * p * p * p + q * q * q * q * q;
  30.  
  31.             if (perfectFifth(result)) {
  32.               System.out.println(m + " " + n + " " + p + " " + q + "→" + result);
  33.  
  34.             }
  35.           }
  36.         }
  37.       }
  38.     }
  39.  
  40.   }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment