博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2^n的第一位数字 soj 3848 mathprac
阅读量:5924 次
发布时间:2019-06-19

本文共 1548 字,大约阅读时间需要 5 分钟。

 Time Limit: 3000 MS    Memory Limit: 65536 K 




                                                      mathprac

Description



One lovely afternoon, Bessie's friend Heidi was helping Bessie

review 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 greater

than 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 calculating

her 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

题意:

就是求2^n的第一位数字;

由于2^n=t*10^k,那么也就是求t的第一位。

log10(2^n)=n*log10(2)

                =log10(t*10^k)

                =log10(t)+k   k为整数

求出n*log10(2)减去k即可求得log10(t),然后求出10^log10(t),对其取整,即为所求。

 
#include
<
iostream
>
#include
<
math.h
>
using
namespace
std;
int
main(
void
)
{
int
A,B;
while
(scanf(
"
%d%d
"
,
&
A,
&
B)
==
2
)
{
int
i;
double
d;
int
digit;
int
p;
for
(i
=
A
+
1
;i
<=
62
;i
++
)
{
d
=
i
*
log10(
2.0
);
p
=
(
int
)(d);
digit
=
(
int
)pow(
10.0
,d
-
p);
if
(digit
==
B)
{
printf(
"
%d\n
"
,i);
break
;
}
}
if
(i
==
63
)
printf(
"
0\n
"
);
}
return
0
;
}
http://www.cnblogs.com/dolphin0520/archive/2011/04/11/2012982.html
你可能感兴趣的文章
【干货】界面控件DevExtreme视频教程大汇总!
查看>>
闭包 !if(){}.call()
查看>>
python MySQLdb安装和使用
查看>>
Java小细节
查看>>
poj - 1860 Currency Exchange
查看>>
chgrp命令
查看>>
Java集合框架GS Collections具体解释
查看>>
洛谷 P2486 BZOJ 2243 [SDOI2011]染色
查看>>
linux 笔记本的温度提示
查看>>
(转)DOTA新版地图6.78发布:大幅改动 增两位新英雄
查看>>
工欲善其事必先利其器SecureCRT+VMware® Workstation_学习笔记
查看>>
文件和目录权限chmod,更改所有者和所属组chown,umask,隐藏权限lsattr/chattr
查看>>
阿里PB级Kubernetes日志平台建设实践
查看>>
怎么把无线由器限
查看>>
Java实现的冒泡排序
查看>>
APP中的第三方“支付”功能该如何测试
查看>>
数值积分中的辛普森方法及其误差估计
查看>>
Web service (一) 原理和项目开发实战
查看>>
跑带宽度多少合适_跑步机选购跑带要多宽,你的身体早就告诉你了
查看>>
[J2MEQ&A]WTK初始化WMAClient报错XXX has no IP address的解释
查看>>