Compute n ! under modulo p | Simple method to compute n ! % p ; Returns value of n ! % p ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int modFact ( int n , int p ) { if ( n >= p ) return 0 ; int result = 1 ; for ( int i = 1 ; i <= n ; i ++ ) result = ( result * i ) % p ; return result ; } int main ( ) { int n = 25 , p = 29 ; cout << modFact ( n , p ) ; return 0 ; }