Description
给出一整数m,求满足10^k<=2^m-1的最大整数k
Input
多组用例,每组用例输入一整数m,以文件尾结束输入(1<=m<=1e5)
Output
对于每组用例,输出满足10^k<=2^m-1的最大整数k
Sample Input
1
64
Sample Output
Case #1: 0
Case #2: 19
Solution
2^m-1(奇数)和10^k(偶数)不可能相等,所以只需要求10^k<=2^m的最大整数k即可,两边取以2为底的对数有k<=m/log2(10),O(1)即可得到答案
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111
int main()
{
int m,k,res=1;
while(~scanf("%d",&m))
{
k=(int)(1.0*m/log2(10));
printf("Case #%d: %d\n",res++,k);
}
return 0;
}