題目連接:http://acm.hdu.edu.cn/showproblem.php?pid=6033
【題意】給定一個數字m,求出滿足10^k<=2^m-1的最大的k。
【分析】對2^m取對數,然後求解該數以10爲底數時冪即可,比賽時考慮多了加了精度判斷,實際不會出現10^k=2^m的情況
【代碼】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define eps 1e-8
#define PI acos(-1.0)
int main(){
int m,cas=1;
while(~scanf("%d",&m)){
if(m==1){
printf("Case #%d: 0\n",cas++);
continue;
}
double tmp=m*log(2.0);
tmp/=log(10.0);
int ans=tmp;
if(tmp-ans<eps)
ans--;
printf("Case #%d: %d\n",cas++,ans);
}
}