We have an inequlity of
P*10^T <= 2^N < (P+1)*10^T
thus log2(P*10^T) <= log2(2^N) < log2((P+1)*10^T),
which is log2(P)+T*log2(10) <= N < log2(P+1)+T*log2(10).
Also, we know that P < 10^(T-1),
that is T > log10(P)+1.
Then, we can brute force on T and find the minmum N.
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
long double ab(long double prf ){
long double lo,up,f,t;
lo=log2l(prf);
up=log2l(prf+1);
f=log2l(10);
t=ceill(log10l(prf+0.5))+1;
for (; ceill(lo+t*f) != floorl(up+t*f); t += 1) {}
return ceill(lo+t*f);
}
int main(){
long double prf;
while(cin>>prf){
printf("%lld\n",(long long)ab(prf));
}
return 0;
}