Smallest number possible by repeatedly multiplying with K or 2 exactly N times starting from 1 | Java program for the above approach ; Function to find the minimum value of X after increment X by K or twice value of X in each of N operations ; Iterate over the range [ 1 , N ] ; If the value of X is less than equal to K ; Otherwise ; Return the minimum value of X ; Driver Code
import java . io . * ; class GFG { public static int minPossibleValue ( int N , int K , int X ) { for ( int i = 1 ; i <= N ; i ++ ) { if ( X <= K ) { X = X * 2 ; } else { X = X + K ; } } return X ; } public static void main ( String [ ] args ) { int N = 7 , K = 4 , X = 1 ; System . out . println ( minPossibleValue ( N , K , X ) ) ; } }