Write the given number in base of x.
If it contains only one 1,it is power of x.
ex : Given M, find if M = 3^x for some positive integer x efficiently. Do not use log, pow etc..
3^n contains only one 1 in the 3-base representation.So write number M in base-3, and check if it contains only one digit(1).
If it contains only one 1,it is power of x.
ex : Given M, find if M = 3^x for some positive integer x efficiently. Do not use log, pow etc..
3^n contains only one 1 in the 3-base representation.So write number M in base-3, and check if it contains only one digit(1).
No comments:
Post a Comment