Store all values of a ^ ( n * i ) of LHS
for ( let i = 1 , cur = an ; i <= n ; ++ i ) { if ( value [ cur ] == 0 ) value [ cur ] = i ; cur = ( cur * an ) % m ; } for ( let i = 0 , cur = b ; i <= n ; ++ i ) {