HDU6033 Add More Zero

本文解析了一道算法题,给定数字m,求满足10^k<=2^m-1的最大k值。通过计算2^m的对数值并转换成以10为底的指数形式来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目连接: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);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值