"Early bird" squares Definition

If you take the sequence of positive integer squares, and concatenate them into a string of digits (i.e. 149162536496481100...), an "early bird" square is one that can be found in this string ahead of its natural position.

For example, 72 (the number 49), can be found at an offset of 2 in the string, although the natural position is at offset 10. Thus 7 is the first "early bird" square.

Note that for it to be considered an "early bird" square, all the digits in the square must occur before the start of the natural position. A match that partially overlaps the natural position does not count.

a(n) is the nth positive integer k such that k2 is an "early bird" square.

Task

Given a positive integer n, output a(n).

You can use 1-based or 0-based indexing, but if you use 0-based indexing, please say so in your answer.

You solution should be able to handle at least as high as a(53) (or if you're using 0-based indexing, a(52)).

Testcases

n     a(n)
1     7
2     8
3     21
4     25
5     46
6     97
7     129
8     161
9     196
10    221
...
13    277
...
50    30015
51    35000
52    39250
53    46111


References


OEIS A181585
JavaScript (ES6), 51 49 45 bytes

1-indexed.

f=(n,s=k='')=&gt;n?f(n-!!s.match(++k*k),s+k*k):k


Demo



f=(n,s=k='')=&gt;n?f(n-!!s.match(++k*k),s+k*k):k

for(n = 1; n &lt;= 20; n++) {
  console.log('a(' + n + ') = ' + f(n))
}




Formatted and commented

f = (                         // f = recursive function taking:
  n,                          //   n = input
  s = k = ''                  //   s = string of concatenated squares, k = counter
) =&gt;                          //
  n ?                         // if we haven't reached the n-th term yet:
    f(                        //   do a recursive call with:
      n - !!s.match(++k * k), //     n decremented if k² is an early bird square
      s + k * k               //     s updated
    )                         //   end of recursive call
  :                           // else:
    k                         //   return k


Non-recursive version, 53 bytes

This one does not depend on your engine stack size.

n=&gt;{for(k=s='';n-=!!(s+=k*k).match(++k*k););return k}


Try it online!