TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
C++ Program for Modular Exponentiation Iteratively. More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | math |
for assert | |
Functions | |
uint64_t | math::power (uint64_t a, uint64_t b, uint64_t c) |
This function calculates a raised to exponent b under modulo c using modular exponentiation. | |
static void | test () |
int | main () |
Main function. | |
C++ Program for Modular Exponentiation Iteratively.
The task is to calculate the value of an integer a raised to an integer exponent b under modulo c.
Example: (4^3) % 5 (where ^ stands for exponentiation and % for modulo) (4*4*4) % 5 (4 % 5) * ( (4*4) % 5 ) 4 * (16 % 5) 4 * 1 4 We can also verify the result as 4^3 is 64 and 64 modulo 5 is 4
Definition in file modular_exponentiation.cpp.
int main | ( | void | ) |
Main function.
Definition at line 86 of file modular_exponentiation.cpp.
|
static |
Function for testing power function. test cases and assert statement.
void
Definition at line 60 of file modular_exponentiation.cpp.