mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Update modular_exponentiation.cpp
This commit is contained in:
parent
d8f2001fd3
commit
af3fadc800
@ -15,15 +15,20 @@
|
|||||||
* We can also verify the result as 4^3 is 64 and 64 modulo 5 is 4
|
* We can also verify the result as 4^3 is 64 and 64 modulo 5 is 4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream> /// for io operations
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @namespace math
|
||||||
|
* @brief Mathematical algorithms
|
||||||
|
*/
|
||||||
|
namespace math {
|
||||||
/**
|
/**
|
||||||
* @brief This function calculates a raised to exponent b
|
* @brief This function calculates a raised to exponent b
|
||||||
* under modulo c using modular exponentiation.
|
* under modulo c using modular exponentiation
|
||||||
* @param a integer base
|
* @param a integer base
|
||||||
* @param b unsigned integer exponent
|
* @param b unsigned integer exponent
|
||||||
* @param c integer modulo
|
* @param c integer modulo
|
||||||
* @return a raised to power b modulo c.
|
* @return a raised to power b modulo c
|
||||||
*/
|
*/
|
||||||
int power(int a, unsigned int b, int c)
|
int power(int a, unsigned int b, int c)
|
||||||
{
|
{
|
||||||
@ -52,6 +57,7 @@ int power(int a, unsigned int b, int c)
|
|||||||
|
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
} // namespace math
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Main function
|
* @brief Main function
|
||||||
@ -65,7 +71,7 @@ int main()
|
|||||||
int m = 13;
|
int m = 13;
|
||||||
|
|
||||||
std::cout << "The value of "<<num1<<" raised to exponent "<<num2<<
|
std::cout << "The value of "<<num1<<" raised to exponent "<<num2<<
|
||||||
" under modulo "<<m<<" is " << power(num1, num2, m);
|
" under modulo "<<m<<" is " << math::power(num1, num2, m);
|
||||||
/// std::cout << "The value of "<<num1<<" raised to exponent "<<num2<<"
|
/// std::cout << "The value of "<<num1<<" raised to exponent "<<num2<<"
|
||||||
/// " under modulo "<<m<<" is " << power(num1, num2, m);
|
/// " under modulo "<<m<<" is " << power(num1, num2, m);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user