You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
782 B
C++

/*
* C++ Program to Implement Euler Theorem
*/
#include <iostream>
#include <vector>
using namespace std;
vector<int> inverseArray(int n, int m)
{
vector<int> modInverse(n + 1, 0);
modInverse[1] = 1;
for (int i = 2; i <= n; i++)
{
modInverse[i] = (-(m / i) * modInverse[m % i]) % m + m;
}
return modInverse;
}
//Main
int main()
{
vector<int>::iterator it;
int a, m;
cout<<"Enter number to find modular multiplicative inverse: ";
cin>>a;
cout<<"Enter Modular Value: ";
cin>>m;
cout<<inverseArray(a, m)[a]<<endl;
}
/*
Enter number to find modular multiplicative inverse: 5
Enter Modular Value: 7
3
------------------
(program exited with code: 1)
Press return to continue