Returns modulo inverse of a with respect to m using extended Euclid Algorithm . Refer below post for details : https : www . geeksforgeeks . org / multiplicative - inverse - under - modulo - m /
function inv ( a , m ) { let m0 = m ; let x0 = 0 ; let x1 = 1 ; if ( m == 1 ) return 0 ;