卡了有點久,看了別人解法才發現這題竟然這麼簡單…
公式如下:
N*10^n < 2^k < (N+1)*10^n
log10(N)+n < k*log10(2) < log10(N+1)+n
log10(N) < k*log10(2)-n < log10(N+1)
find if k exist
另外,k 如果最大值設 32,767 (int)會 WA ,如果設成 2,147,483,647 (long)就可以順利 AC
拿來放些筆記或有關程設的東東...
N*10^n < 2^k < (N+1)*10^n
log10(N)+n < k*log10(2) < log10(N+1)+n
log10(N) < k*log10(2)-n < log10(N+1)
find if k exist
Blogger Templates created by Deluxe Templates.
2 則留言:
請問一下 這樣n跟k兩個變數 一個式子怎麼解?
Output
For every one of these integers a line containing the smallest positive integer E such that the first digits of 2E are precisely the digits of N, or, if there is no one, the sentence ``no power of 2".
張貼留言