This project performs primality tests on Fermat numbers, defined as:
The program offers two modes of operation. The first one provides a primality test. In case the Fermat number is composite, the smallest prime factor is printed. In the second mode, we look for Fermat numbers that are divisible by
- Euler Method: Efficiently finds the smallest prime factor of Fermat numbers. This method is used in the primality test.
- Finding Fermat Numbers: Since k · 2l + 1 can be a divisor of any Fermat number Fn with n < l, we search for all Fermat numbers that could potentially be divisible by it.
- Optional Output: Supports a flag to print the corresponding Fermat number and Fermat factor.
- C++ Compiler (e.g.,
g++
)
- GMP Library (GNU Multiple Precision Arithmetic Library)
- Installation Script Run install.sh to install dependencies automatically
The project includes a Makefile
to simplify the compilation process. Below are the available commands:
- Compile the Program:
To compile the program, run:
make
This will generate the executable in the ./bin/ folder.
- Clean Build Files: To remove all compiled object files and the executable, run:
make clean
After compiling, run the program using:
./bin/fermat_pf_test -m [MODE] -i [FERMAT INDEX] -k [k] -l [l] -n
where
- -m [Mode]: Mode to use the program:
p
for primality test.f
for looking for Fermat Numbers with a specific factor. (Primality method is the default).
- -i [FERMAT INDEX]: Index of the Fermat number to be tested.
- -k [k]: the k on the specific factor ( k \cdot 2^l + 1 ).
- -l [l]: the l on the specific factor ( k \cdot 2^l + 1 ).
- -n: Optional flag to print the corresponding Mersenne number.
- If the primality mode is selected, it will run the Euler method to find the smallest prime factor and output whether Fn is prime.
- If the find fermat numbers with a specific factor mode is selected, it will run and output all Fermat numbers that has a factor ( k \cdot 2^l + 1 ).