Minimize product of first N | JavaScript program for the above approach ; Function to find the minimum product of 1 to N - 1 after performing the given operations ; Initialize ans with 1 ; Multiply ans with N - 2 ( ( N - 4 ) / 2 ) times ; Multiply ans with N - 1 and N - 2 once ; Print ans ; Given Number N ; Function Call
let mod = 1e9 + 7 ; function minProduct ( n ) { let ans = 1 ; for ( let i = 1 ; i <= Math . floor ( ( n - 4 ) / 2 ) ; i ++ ) { ans = ( 1 * ans * ( n - 2 ) ) % mod ; } ans = ( 1 * ans * ( n - 2 ) * ( n - 1 ) ) % mod ; document . write ( ans + " " ) ; } let N = 8 ; minProduct ( N ) ;