题目链接:VJ: https://vjudge.net/problem/HDU-6033 HDU原链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=759题意: 给定一个m(1 <= m <= 1e5) 问2^m - 1和10^k长度相同的k是多少
思想:对于一个数x来说, log10(x) 就等于k, 就要考虑这个-1, 当只有在10, 100,...10的幂次的时候, 位数才会降低, 所以-1对于2^m并没有影响。
所以答案就是 m* log(2.0)
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;
int n;
int main(){
int cas = 0;
while(~scanf("%d", &n)){
int k = n * log10(2.0);
printf("Case #%d: %d\n", ++cas, k);
}
return 0;
}