### Ishtiaq11's blog

By Ishtiaq11, history, 5 years ago,

I have two integer b,n. I need to check if the number n is integer power of number b. For example: 100 is an integer power of 10. As 10^2 = 100. But 110 is not an integer power of 10. How to determine this in coding?

• -7

 » 5 years ago, # |   +2 Try to do like this:Find log2 of n. Then divide it by log2 of b.If the result is integer, then n is power of b.
•  » » 5 years ago, # ^ |   0 Thank you.I know a way how to check if a number is an integer or not.  if int(res) == ceil(res): integer else: not integer if there is another way, please suggest me.
•  » » » 5 years ago, # ^ |   0 b divides a if ( (a/b)*b == a)
•  » » » » 5 years ago, # ^ |   +3 Its more efficient. Thanks for helping.
 » 5 years ago, # | ← Rev. 2 →   +7 k=b while(k
•  » » 5 years ago, # ^ |   +3 Thank you. But I can't understand the condition for avoiding overflow. Can you please explain why this condition is needed? If I comment out this line, what error will occur.
•  » » » 5 years ago, # ^ |   0 n = 2*1e18 and b = 1e9
•  » » » » 5 years ago, # ^ |   +3 Thanks.
•  » » » 5 years ago, # ^ |   0 HelloCheck this problem : http://codeforces.com/contest/614/problem/A ,and you will see why this condition is important, and how can overflow occur.
•  » » » » 5 years ago, # ^ |   +1 Thanks