Please enter your email address or userHandle.
Given two integers N and M you have to find out an integer which is a power of M and is nearest to N.
Note: If there are multiple answers possible to, print the greatest number possible.
N = 6, M = 3
Both 3 (31) and 9 (32) are equally
near to 6. But 9 is greater,
so the Output is 9.
N = 3, M = 2
Both 2 (21) and 4 (22) are equally
near to 3. But 4 is greater,
so the Output is 4.
You don't need to read input or print anything. Your task is to complete the function nearestPower() which takes 2 Integers N and M as input and returns the answer.
Expected Time Complexity: O(max(log(N),log(M)))
Expected Auxiliary Space: O(1)
1 <= N,M <= 109
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.