Find the minimum number to be added to N to make it a power of K | C ++ program to find the minimum number to be added to N to make it a power of K ; Function to return the minimum number to be added to N to make it a power of K . ; Computing the difference between then next greater power of K and N ; Driver code
#include <bits/stdc++.h> NEW_LINE #define ll  long long int NEW_LINE using namespace std ; int minNum ( int n , int k ) { int x = ( int ) ( log ( n ) / log ( k ) ) + 1 ; int mn = pow ( k , x ) - n ; return mn ; } int main ( ) { int n = 20 , k = 5 ; cout << minNum ( n , k ) ; return 0 ; }