## Minimum operation required to make N as sum of distinct powers of X

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article
Given an integer N and a base X, the task is to find the minimum number of operations required to represent N as a sum of the distinct powers of X. In each operation, you can either increment or decrement N. You are allowed to make the given operation any number of timesExamples:Input: N = 7, X = 3 Output: 3Explanation: It will be optimal to increment N by 3 in 3 operations. Then, N = 10 = 30 + 33. Input: N = 53, X = 7 Output:…