(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.


f = Compile[{{ll, _Integer}, {n, _Integer}}, 
   Module[{l, digitcount, log10power, raised, found, firstdigits, pwr = 2},
    l = Abs[ll];
    digitcount = Floor[Log[10, l]];
    log10power = Log[10, pwr];
    raised = -1;
    found = 0;
    While[found < n,
     raised++;
     firstdigits = Floor[10^(FractionalPart[log10power raised] + digitcount)];
     If[firstdigits == l,
      found += 1;
      ]
     ];
    Return[raised]
    ]
 ];
f[12, 1]
f[12, 2]
f[123, 45]
f[123, 12345]
f[123, 678910]