Minimize positive product of two given numbers by at most N decrements | C # program to implement the above approach ; Function to minimize the product of two numbers ; Reducing X , N times , minimizes the product ; Reduce X to 1 and reduce remaining N from Y ; Reducing Y , N times , minimizes the product ; Reduce Y to 1 and reduce remaining N from X ; Driver Code
using System ; class GFG { static int minProd ( int X , int Y , int N ) { if ( X <= Y ) { if ( N < X ) return ( X - N ) * Y ; else { return Math . Max ( Y - ( N - X + 1 ) , 1 ) ; } } if ( Y >= N ) return ( Y - N ) * X ; return Math . Max ( X - ( N - Y + 1 ) , 1 ) ; } public static void Main ( String [ ] args ) { int X = 47 , Y = 42 , N = 167 ; Console . WriteLine ( minProd ( X , Y , N ) ) ; } }