hdu6033

来源:互联网 发布:新概念英语4 知乎 编辑:程序博客网 时间:2024/06/08 18:27

hdu 6033

There is a youngster known for amateur propositions concerning several mathematical hard problems.
Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to support calculations of integers between 0 and (2m−1) (inclusive).
As a young man born with ten fingers, he loves the powers of 10 so much, which results in his eccentricity that he always ranges integers he would like to use from 1 to 10k (inclusive).
For the sake of processing, all integers he would use possibly in this interesting problem ought to be as computable as this supercomputer could.
Given the positive integer m, your task is to determine maximum possible integer k that is suitable for the specific supercomputer.

说白了,就是计算 2n 有多少位。
开始因为210103考虑用ans = n % 10 * 3,余数单独计算是否够10
不过2100010301 不符合上式
那换个思路,求2n的位数的话,直接求/lg2n就好了
这道题就只是一个需要化简的数学题

#include <iostream>#include <math.h>using namespace std;int main(){    int expon;    double tenLogtwo;    int i = 1;double ans;    for (;cin >> expon;i++)    {        cout << "Case #" << i << ": ";        tenLogtwo = log(2) / log(10);        ans = tenLogtwo * expon;        cout << (int)ans << "\n";    }    return 0;}
原创粉丝点击