701
枚举需要的位数2ans > n * 10i && 2ans < (n + 1) * 10i , i 的初值为log10(n) + 2。而符合条件的一个整数ans就是答案。
log2(2ans) = ans, log2(n * 10i) = log2(n) + i * log2(10),log2((n + 1)* 10i) = log2(n + 1) + i * log2(10)。
//============================================================================ // Name : 701.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <cmath> #include <cstdio> using namespace std; double n, a, b; int tag; int main() { freopen("a.txt", "r", stdin); while(scanf("%lf", &n) == 1){ tag = 0; for(int i = log10(n)+2; !tag ;i++){ a = log10(n*1.0)/log10(2.0)+i*log(10.0)/log(2.0); b = log10(n+1.0)/log10(2.0)+i*log(10.0)/log(2.0); for(int j = a;j < b&& !tag;j++){ if(j >= a&&j < b){ printf("%d\n", j); tag = 1; break; } } } } return 0; }