题目686:2的幂
https://s1.ax1x.com/2020/05/17/Y2zlq0.pnghttps://s1.ax1x.com/2020/05/17/Y2zQrq.png 本帖最后由 咸鱼c1 于 2020-5-17 21:17 编辑
好难,只能写个循环跑一跑{:10_266:}{:10_266:},等个题解
def fun(L,n):
i=1
L=str(L)
le=len(L)
while(n):
temp=str(1<<i)
temp=temp
i+=1
if(temp==L):
n-=1
return i-1
前40个P(123,n):
他们之间差值:
发现只有三种差值
{:10_243:}
本帖最后由 咸鱼c1 于 2020-5-18 00:57 编辑
P(123,678910)=193060223{:10_279:}{:10_279:}
判断2^j>=123*10^m and 2^j<124*10^m,以10为底取对数,保留前三位
j*lg2+2-m.floor(j*lg2)>=lg123 and j*lg2+2-m.floor(j*lg2)<lg124
import math as m
def fun(n):
lg2=m.log(2)/m.log(10)
lg123=m.log(123)/m.log(10)
lg124=m.log(124)/m.log(10)
def isok(y):
temp=2+y*lg2-m.floor(y*lg2)
if(temp>=lg123 and temp<lg124):
return True
return False
i=90
cnt=1
while(n):
if(cnt==n):
return i
if(isok(i+196)):
cnt+=1
i+=196
elif(isok(i+289)):
cnt+=1
i+=289
elif(isok(i+485)):
cnt+=1
i+=485 咸鱼c1 发表于 2020-5-18 00:52
P(123,678910)=193060223
判断2^j>=123*10^m and 2^j=lg123 and j*lg2+2-m.floor(j*l ...
恭喜,答案正确!{:10_298:}
这是我发帖子以来第一道有人解出来的题!{:10_275:}
以后给你评分{:10_307:} #include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
double ld2 = log10(2.0), ld123 = log10(123.0), ld124 = log10(124.0);
int nCount = 0;
while (nCount < 678910)
{
long long l = ceil(ld123 / ld2);
long long u = floor(ld124 / ld2);
for (long long i = l; i <= u; ++i)
{
++nCount;
if (nCount == 678910)
{
cout << i << endl;
break;
}
}
ld123 += 1.0;
ld124 += 1.0;
}
return 0;
}
页:
[1]