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
af3fadc800
commit
365e9a823a
@ -30,9 +30,10 @@ namespace math {
|
||||
* @param c integer modulo
|
||||
* @return a raised to power b modulo c
|
||||
*/
|
||||
int power(int a, unsigned int b, int c)
|
||||
|
||||
uint64_t power(uint64_t a, uint64_t b, uint64_t c)
|
||||
{
|
||||
int ans = 1; /// Initialize the answer to be returned
|
||||
uint64_t ans = 1; /// Initialize the answer to be returned
|
||||
|
||||
a = a % c; /// Update a if it is more than or
|
||||
/// equal to c
|
||||
@ -66,9 +67,9 @@ int power(int a, unsigned int b, int c)
|
||||
int main()
|
||||
{
|
||||
/// Give two numbers num1, num2 and modulo m
|
||||
int num1 = 2;
|
||||
int num2 = 5;
|
||||
int m = 13;
|
||||
uint64_t num1 = 2;
|
||||
uint64_t num2 = 5;
|
||||
uint64_t m = 13;
|
||||
|
||||
std::cout << "The value of "<<num1<<" raised to exponent "<<num2<<
|
||||
" under modulo "<<m<<" is " << math::power(num1, num2, m);
|
||||
@ -77,4 +78,3 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user