Code Library Of Others/sgtlaugh/Modular Inverse.cpp
int mod_inverse(int a, int m){
    if ((a < 2)) return a;
    int res = (((1LL - (long long)m * mod_inverse(m % a, a)) / (a % m)) + m) % m;
    return res;
}
/* Caution, crashes when m = 1, crashes sometimes when a = m
   Sometimes returns 0 if a and m are not co-primes
   Unstable but extremely elegant
*/
Caution, crashes when m = 1, crashes sometimes when a = m
Sometimes returns 0 if a and m are not co-primes
Unstable but extremely elegant
Caution crashes when m = 1 crashes sometimes when a = m Sometimes returns 0 if a and m are not co - primes Unstable but extremely elegant
int mod_inverse(int a, int m){
    if ((a < 2)) return a;
    int res = (((1LL - (long long)m * mod_inverse(m % a, a)) / (a % m)) + m) % m;
    return res;
}
int mod_inverse ( int a , int m ) { if ( ( a < 2 ) ) return a ; int res = ( ( ( 1LL - ( long long ) m * mod_inverse ( m % a , a ) ) / ( a % m ) ) + m ) % m ; return res ; }
Caution, crashes when m = 1, crashes sometimes when a = m
Sometimes returns 0 if a and m are not co-primes
Unstable but extremely elegant
Caution crashes when m = 1 crashes sometimes when a = m Sometimes returns 0 if a and m are not co - primes Unstable but extremely elegant