Compute the maximum power with a given condition | 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE int calculate ( ll int n , ll int k , ll int m , ll 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 ) ; } int main ( ) { ll N = 1 , K = 2 , M = 5 ; cout << calculate ( N , K , M , 0 ) ; return 0 ; }