XDOJ1053 - Math Practice

Description

   One lovely afternoon, Bessie's friend Heidi was helping Bessiereview for her upcoming math exam.

     Heidi presents two integers A (0 <= A <= 45) and B (1 <= B <= 9)to Bessie who must respond with an integer E in the range 1..62.E is the smallest integer in that range that is strictly greaterthan A and also has B as the first digit of 2 raised to the E-th power. If there is no answer, Bessie responds with 0.

    Help Bessie correctly answer all of Heidi's questions by calculatingher responses.

    By way of example, consider A=1 and B=6. Bessie might generate a table

like this:

         E         2^E    First digit of 2^E

         2          4            4

         3          8            8

         4         16            1

         5         32            3

         6         64            6      <-- matches B

Thus, E=6 is the proper answer.

NOTE: The value of 2^44 does not fit in a normal 32-bit integer.

 

Input

Line 1: Two space-separated integers: A and B

Output

Line 1: A single integer E calculated as above

Sample Input

1 6

Sample Output

6

Hint

注意换行

解题思路:

题意非常清楚,2^E的第一个数等于B,而且E>A

 

#include<iostream>
using namespace std;

int main()
{

    int A,B;
    cin>>A>>B;
    long long factor = 1;
    long long powE = 2;
    int E = 1;
    while(E<=62&&(powE/factor!=B||E<=A))
    {
        ++E;
        powE *= 2;
        while(powE/factor>9)
            factor *= 10;

    }
    if(E>62)
        cout<<0<<endl;
    else
        cout<<E<<endl;

    return 0;
}

 

最后欢迎大家访问我的个人网站:1024s

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值