Compute the maximum power with a given condition | Java program for Compute maximum power to which K can be raised so that given condition remains true ; Function to return the largest power ; If n is greater than given M ; If n == m ; Checking for the next power ; Driver Code
class GFG { static int calculate ( int n , int k , int m , int power ) { if ( n > m ) { if ( power == 0 ) return 0 ; else return power - 1 ; } else if ( n == m ) return power ; else return calculate ( n * k , k , m , power + 1 ) ; } public static void main ( String [ ] args ) { int N = 1 , K = 2 , M = 5 ; System . out . println ( calculate ( N , K , M , 0 ) ) ; } }