答案就是 ⌊log10(2m−1)⌋,注意到不存在 10k=2m ,所以⌊log10(2m−1)⌋=⌊log102m⌋=⌊mlog102⌋,这样做的时间复杂度是
O(1) 。
当时我用的暴力打表也可以ac
//
// main.cpp
// A - Add More Zero
//
// Created by wenhan on 2017/7/28.
// Copyright © 2017年 wenhan. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int t;
int count=1;
while (cin>>t) {
int n=log(2)/log(10)*t;
printf("Case #%d: %d\n",count++,n);
}
// insert code here...
//std::cout << "Hello, World!\n";
return 0;
}