OFFSET
0,3
COMMENTS
If 4*(n+1) < 10^d then a(n) < (n+1)*10^d. - Robert Israel, Aug 01 2014
LINKS
Zak Seidov, Table of n, a(n) for n = 0..100000 (first 10000 terms from Chai Wah Wu)
EXAMPLE
Among the first 100001 terms, the largest is a(99999) = 99999515529 = 316227^2. - Zak Seidov, May 22 2016
MAPLE
a:= proc(n) local k, d, x;
if issqr(n) then return n
else for d from 1 do
for k from 0 to 10^d-1 do
x:= 10^d*n+k;
if issqr(x) then return x fi
od
od
fi
end proc:
seq(a(n), n=1..100); # Robert Israel, Jul 31 2014
MATHEMATICA
Table[With[{d = IntegerDigits@ n}, k = 1; While[Or[IntegerLength[k^2] < Length@ d, Take[IntegerDigits[k^2], Length@ d] != d], k++]; k^2], {n, 49}] (* Michael De Vlieger, May 23 2016 *)
PROG
(Python)
n = 1
while n < 100:
for k in range(10**3):
if str(k**2).startswith(str(n)):
print(k**2, end=', ')
break
n += 1 # Derek Orr, Jul 31 2014
(Python)
from gmpy2 import isqrt
def A018796(n):
if n == 0:
return 0
else:
d, nd = 1, n
while True:
x = (isqrt(nd-1)+1)**2
if x < nd+d:
return int(x)
d *= 10
nd *= 10 # Chai Wah Wu, May 23 2016
(PARI) \\Set precision high enough (for the cases where n+1 is a square)!
a(n) = {my(v=vector(2)); if(issquare(n), return(n), v=[sqrt(n), sqrt(n+1-(10^-((#digits(n)+7))))]; while(ceil(v[1])>floor(v[2]), v*=sqrt(10))); ceil(v[1])^2
} \\ David A. Corneth, May 22 2016
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
EXTENSIONS
a(0)=0 prepended by Zak Seidov, May 22 2016
STATUS
approved