Maximize count of distinct profits possible by N transactions | Java program for the above approach ; Function to count distinct profits possible ; Stores the minimum total profit ; Stores the maximum total profit ; Return count of distinct profits ; Driver code ; Input ; Function call
import java . util . Arrays ; class GFG { static int numberOfWays ( int N , int X , int Y ) { int S1 = ( N - 1 ) * X + Y ; int S2 = ( N - 1 ) * Y + X ; return ( S2 - S1 + 1 ) ; } public static void main ( String [ ] args ) { int N = 3 ; int X = 13 ; int Y = 15 ; System . out . println ( numberOfWays ( N , X , Y ) ) ; } }