Add More Zero
There is a youngster known for amateur propositions concerning several mathematical hard problems.
Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to support calculations of integers between
0
0 and
(2m−1)
(2m−1) (inclusive).
As a young man born with ten fingers, he loves the powers of
10
10 so much, which results in his eccentricity that he always ranges integers he would like to use from
1
1 to
10k
10k (inclusive).
For the sake of processing, all integers he would use possibly in this interesting problem ought to be as computable as this supercomputer could.
Given the positive integer
m
m, your task is to determine maximum possible integer
k
k that is suitable for the specific supercomputer.
1 64
Case #1: 0 Case #2: 19
官方题解:
1001. Add More Zero
答案是 ⌊log10(2m−1)⌋\left \lfloor \log_{10}(2^m - 1) \right \rfloor⌊log10(2m−1)⌋,注意到不存在10k=2m10^k = 2^m10k=2m ,所以⌊log10(2m−1)⌋=⌊log102m⌋=⌊mlog102⌋\left \lfloor \log_{10}(2^m - 1) \right \rfloor = \left \lfloor \log_{10}{2^m} \right \rfloor = \left \lfloor m \log_{10}{2} \right \rfloor⌊log10(2m−1)⌋=⌊log102m⌋=⌊mlog102⌋,这样做的时间复杂度是 O(1) 。
好吧其实就是 m*log10(2)