text: A naive method to find modular multiplicative inverse of ' a ' under modulo ' prime '
code: < ? php function modInverse ( int $ a , int $ prime ) { $ a = $ a % $ prime ; for ( $ x = 1 ; $ x < $ prime ; $ x ++ ) if ( ( $ a * $ x ) % $ prime == 1 ) return $ x ; return -1 ; } function printModIverses ( $ n , $ prime ) { for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) echo modInverse ( $ i , $ prime ) , " ▁ " ; }