Evaluate the expression ( N1 * ( N | Python 3 program to implement the above approach ; Function to find the value of the expression ( N ^ 1 * ( N 1 ) ^ 2 * ... * 1 ^ N ) % ( 109 + 7 ) . ; factorial [ i ] : Stores factorial of i ; Base Case for factorial ; Precompute the factorial ; dp [ N ] : Stores the value of the expression ( N ^ 1 * ( N 1 ) ^ 2 * ... * 1 ^ N ) % ( 109 + 7 ) . ; Update dp [ i ] ; Return the answer . ; Driver Code ; Function call
mod = 1000000007 NEW_LINE def ValOfTheExpression ( n ) : NEW_LINE INDENT global mod NEW_LINE factorial = [ 0 for i in range ( n + 1 ) ] NEW_LINE factorial [ 0 ] = 1 NEW_LINE factorial [ 1 ] = 1 NEW_LINE for i in range ( 2 , n + 1 , 1 ) : NEW_LINE INDENT factorial [ i ] = ( ( factorial [ i - 1 ] % mod ) * ( i % mod ) ) % mod NEW_LINE DEDENT dp = [ 0 for i in range ( n + 1 ) ] NEW_LINE dp [ 1 ] = 1 NEW_LINE for i in range ( 2 , n + 1 , 1 ) : NEW_LINE INDENT dp [ i ] = ( ( dp [ i - 1 ] % mod ) * ( factorial [ i ] % mod ) ) % mod NEW_LINE DEDENT return dp [ n ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE print ( ValOfTheExpression ( n ) ) NEW_LINE DEDENT