This project implements a Java program to search for near misses to Fermat's Last Theorem. The program takes two inputs from the user:
- n (the exponent, where 2 < n < 12)
- k (the upper limit for x and y values, where k > 10)
The program iterates over values of x and y (from 10 to k), calculating x^n + y^n and comparing the result to z^n or (z+1)^n. It then identifies the smallest "relative miss" where the sum x^n + y^n closely matches an integer power.
This project demonstrates numerical techniques to explore potential near-miss solutions to Fermat's Last Theorem for specific cases. While Fermat's Last Theorem famously states that there are no integer solutions for x^n + y^n = z^n for n > 2, this program finds cases where the sum is close to an integer power.
- Main file:
FermatNearMiss.java
- Input: Two user-provided inputs:
n
(exponent) andk
(limit for x, y values). - Output: The program outputs the smallest "relative miss" and the corresponding values of x, y, and z.
- Supports any integer exponent n where 2 < n < 12.
- Supports large ranges of x and y (up to a value of k as determined by the system's ability to handle large integers).
- Displays detailed output of misses and relative errors for each combination of x, y, and z.
- Prevents overflow by limiting k based on n and the system's maximum long value.
-
Prerequisites:
- Ensure you have Java JDK installed.
- Basic knowledge of command-line/terminal commands.
-
Clone the Repository:
git clone https://github.com/DeviSreeDornala/Assignment-1 cd Fermat-Near-Miss-Finder
-
Compile the Program:
javac FermatNearMiss.java
-
Run the Program:
java FermatNearMiss
You will be prompted to enter two values:
n
(Exponent, where 2 < n < 12)k
(Upper limit for x and y, where k > 10)
-
Example Output:
Enter the value of n (2 < n < 12): 3 Enter the value of k (k > 10): 20 x: 10, y: 10, z: 14, Miss: 4, Relative Miss: 0.0001830 x: 10, y: 11, z: 14, Miss: 31, Relative Miss: 0.0012379 ... Smallest Relative Miss: x: 10, y: 10, z: 14, Miss: 4, Relative Miss: 0.0001830
- The program is computationally intensive for large values of k.
- Java's
double
precision may introduce rounding errors for very large calculations. - The current implementation caps k to avoid overflow based on the system's
Long.MAX_VALUE
.
Programmer 1: Aasritha Thota Programmer 2: Devi Sree Dornala