PE-CN / pe-cn-comments

2 stars 0 forks source link

Problem 686 | Project Euler | #688

Open sx349 opened 3 years ago

sx349 commented 3 years ago

https://pe-cn.github.io/686/

Problem 686 Powers of Two$2^7=128$ is the first power of two whose leading digits are “$12$”.The next power of two whose leading digits are “$12$” is $2^{80}$. Define $p(L, n)$ to be the $n$th-smalle

shangkelingxiang commented 2 years ago
from numba import njit
@njit
def p(prefix,num):
  v=1
  j=0
  while num>0:
    v*=2
    j+=1
    if v>1000:
      v/=10
    if int(v)==prefix:
      num-=1
  return j
print(p(123, 678910))
yuandi42 commented 3 months ago

PARI/GP 穷举:

p2(L, n)={
    my(i = 0, p = 1, count = 0, u = 10^ceil(log(L)/log(10)));
    while(count<n,
            p*=2;
            i++;
            while(p >= u, p /= 10.0);
            if(floor(p) == L, count++);
         );
    i
};

BTW 我在 pe 的 thread 上看到有人发现 p(123, x) 有一定的规律性,写得很详细,值得一看。