Minimize product of first N | C ++ 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 ; Driver Code ; Given Number N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int mod = 1e9 + 7 ; void minProduct ( int n ) { int ans = 1 ; for ( int i = 1 ; i <= ( n - 4 ) / 2 ; i ++ ) { ans = ( 1LL * ans * ( n - 2 ) ) % mod ; } ans = ( 1LL * ans * ( n - 2 ) * ( n - 1 ) ) % mod ; cout << ans << endl ; } int main ( ) { int N = 8 ; minProduct ( N ) ; return 0 ; }