text: Trick for modular division ( ( x1 * x2 ... . xn ) / b ) mod ( m ) | To run this code , we need to copy modular inverse from below post . https : www . geeksforgeeks . org / multiplicative - inverse - under - modulo - m / ; naive method - calculating the result in a single line ; modular_inverse ( ) is a user defined function that calculates inverse of a number ; it will use extended Eucledian algorithm or Fermats Little Theorem for calculation . MMI of 120 under division by 1000000007 will be 808333339
code: int main ( ) { long int naive_answer = ( ( long int ) ( 55555 * 55554 * 55553 * 55552 * 55551 ) / 120 ) % 1000000007 ; long int ans = 1 ; long int i = modular_inverse ( 120 , 10000007 ) ; for ( int i = 0 ; i < 5 ; i ++ ) ans = ( ans * ( 55555 - i ) ) % 1000000007 ; ans = ( ans * i ) % 1000000007 ; cout << " Answer ▁ using ▁ naive ▁ method : ▁ " << naive_answer << endl ; cout << " Answer ▁ using ▁ multiplicative " << " ▁ modular ▁ inverse ▁ concept : ▁ " << ans ; return 0 ; }