This project is a C# program for calculating fast modular exponentiation, i.e. the result of raising a base number to an exponent and then taking the modulus, as in
- User Input: Prompts the user to enter the base, exponent, and modulus.
- Efficient Algorithm: Implements exponentiation by squaring.
- Detailed Output: Displays intermediate steps and final result.
- Unit Tests: Includes comprehensive unit tests to ensure correctness.
The formula for modular exponentiation is:
where:
a
is the base number,b
is the exponent,n
is the modulus.
- Clone the repository.
- Open a terminal or command prompt.
- Navigate to the project directory (
FastModularExponentiation
) - Compile the program using the following command
dotnet build
- Run the program using the following command:
dotnet run
Enter a: 2
Enter exponent: 10
Enter modulo: 1000
i | x | a | t_i
0 | 1 | 2 | 0
1 | 1 | 4 | 1
2 | 4 | 16 | 0
3 | 4 | 256 | 1
4 | 24 | 536 | -
Result: 24
Unit tests are included to validate the correctness of the algorithm. These tests cover various scenarios to ensure accurate results for different inputs. Follow these steps to execute the unit tests:
- Open a terminal or command prompt.
- Navigate to the directory containing the solution file (
FastModularExponentiation
). - Run the command
dotnet test
.
This project is licensed under the The MIT License. See the LICENSE file for more details.