Find p such that 2^p starts with n

Revision en1, by prathams, 2015-07-04 16:55:27

Given value of n, how can we find the power(p) of 2 such that the result 2^p starts with n.

For ex —

n = 12 then answer is 7 i.e., 2^7 = 128.

n = 82 then answer is 209 i.e., 2^209 = 822752278660603021.........

If no such power exist then p should be -1.

I have coded it, but giving WA and TLE on some test cases. Here is the link to my code : link

How can we find power efficiently ? I got this problem on link

Tags math, number theory

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English prathams 2015-07-05 15:42:05 172
en1 English prathams 2015-07-04 16:55:27 540 Initial revision (published)