(This task is taken from a   Project Euler   problem.)

(All numbers herein are expressed in base ten.)


27   =   128   and   7   is
the first power of   2   whose leading decimal digits are   12.

The next power of   2   whose leading decimal digits
are   12   is   80,

280   =   1208925819614629174706176.



Define        p(L,n)      to be the  nth-smallest
value of    j    such that the base ten representation
of    2j    begins with the digits of    L .

    So   p(12, 1) =  7    and
         p(12, 2) = 80



You are also given that:

         p(123, 45)   =   12710



Task

   find: 
     p(12, 1)  
     p(12, 2)  
     p(123, 45)  
     p(123, 12345)  
     p(123, 678910)  
   display the results here, on this page.


global FAC
FAC = 0.30102999566398119521373889472449302677
 
print p(12, 1)
print p(12, 2)
print p(123, 45)
print p(123, 12345)
print p(123, 678910)
end
 
function p(L, n)
    cont = 0 : j = 0
    LS = string(L)
    while cont < n
        j += 1
        x = FAC * j
        if x < length(LS) then continue while
        y = 10^(x-int(x))
        y *= 10^length(LS)
        digits = string(y)
        if left(digits,length(LS)) = LS then cont += 1
    end while
    return j
end function