Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Test { // Euler's conjecture
- // Lander and Parkin's counter example for n=5
- static final int RANGE = 400; // all fifth power of up to 400
- static long[] fifths = new long[RANGE]; // array to hold them
- static void makeFifths() { // fill array
- for (long i = 0; i < RANGE; i++) {
- fifths[(int) i] = i * i * i * i * i;
- }
- }
- static boolean perfectFifth(long n) { // is n a perfect fifth power?
- // look in the array
- return (Arrays.binarySearch(fifths, n) > 0);
- }
- public static void main(String args[]) {
- makeFifths();
- for (long m = 1; m < RANGE; m++) {
- for (long n = m; n < RANGE; n++) {
- for (long p = n; p < RANGE; p++) {
- for (long q = p; q < RANGE; q++) {
- long result = m * m * m * m * m + n * n * n * n * n + p * p * p * p * p + q * q * q * q * q;
- if (perfectFifth(result)) {
- System.out.println(m + " " + n + " " + p + " " + q + "→" + result);
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment