Created
February 12, 2016 18:59
-
-
Save abdalimran/59557e27d99d35af75ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Bismillah hir rahmanir raheem. Thanks to Allah for everything. | |
Coder: Abdullah Al Imran | |
Email: [email protected] */ | |
#include<bits/stdc++.h> | |
using namespace std; | |
//1. Brute Force | |
int modInverse(int a, int m) | |
{ | |
a%=m; | |
for(int x=1; x<m; x++) | |
{ | |
if((a*x)%m == 1) | |
return x; | |
} | |
} | |
//Recursive Method Using Extended Euclidean Algorithm | |
pair<int, pair<int, int> > extendedEuclid(int a, int b) | |
{ | |
if(a == 0) | |
return make_pair(b, make_pair(0, 1)); | |
pair<int, pair<int, int>>p; | |
p = extendedEuclid(b%a,a); | |
return make_pair(p.first, make_pair(p.second.second - p.second.first*(b/a), p.second.first)); | |
} | |
int modInverse(int a, int m) | |
{ | |
return (extendedEuclid(a,m).second.first + m)%m; | |
} | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment