From 6e6bb63a962144f774f1e253e8cd232df1eed760 Mon Sep 17 00:00:00 2001 From: suchet kochhar <54278744+suchetkochhar@users.noreply.github.com> Date: Wed, 28 Oct 2020 01:38:31 +0530 Subject: [PATCH 1/2] Create Fermat's little theorem --- Miscellaneous/Fermat's little theorem | 1 + 1 file changed, 1 insertion(+) create mode 100644 Miscellaneous/Fermat's little theorem diff --git a/Miscellaneous/Fermat's little theorem b/Miscellaneous/Fermat's little theorem new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Miscellaneous/Fermat's little theorem @@ -0,0 +1 @@ + From 50b978ff7307d2a094e47d2eedad37534920ba19 Mon Sep 17 00:00:00 2001 From: suchet kochhar <54278744+suchetkochhar@users.noreply.github.com> Date: Wed, 28 Oct 2020 01:50:16 +0530 Subject: [PATCH 2/2] inverse.cpp wrote a code to find the multiplicative inverse of a number under the modulus of another number , given that latter is prime . --- Miscellaneous/Fermat's little theorem | 1 - Miscellaneous/inverse.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) delete mode 100644 Miscellaneous/Fermat's little theorem create mode 100644 Miscellaneous/inverse.cpp diff --git a/Miscellaneous/Fermat's little theorem b/Miscellaneous/Fermat's little theorem deleted file mode 100644 index 8b13789..0000000 --- a/Miscellaneous/Fermat's little theorem +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Miscellaneous/inverse.cpp b/Miscellaneous/inverse.cpp new file mode 100644 index 0000000..4ad0985 --- /dev/null +++ b/Miscellaneous/inverse.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; +int pow(int a, int b , int m){ +if(b==0){ +return 1;} +int x=pow(a,b/2,m)%m; +x=(x*x)%m; +if(b%2==0){ +return x;} +else{ +return (x*a)%m;} + +} +int modInverse(int a, int m) { + return pow(a, m - 2, m); +} +int main() { + int a, m; + cout<<"Enter number to find modular multiplicative inverse: "; + cin>>a; + cout<<"Enter Modular Value: "; + cin>>m; + cout<