%I #50 Nov 04 2023 08:46:49
%S 0,1,25,36,4,529,64,729,81,9,100,1156,121,1369,144,1521,16,1764,1849,
%T 196,2025,2116,225,2304,2401,25,2601,2704,289,2916,3025,3136,324,3364,
%U 3481,35344,36,3721,3844,3969,400,41209,4225,4356,441,45369,4624,4761,484,49
%N Smallest square that begins with n.
%C If 4*(n+1) < 10^d then a(n) < (n+1)*10^d. - _Robert Israel_, Aug 01 2014
%H Zak Seidov, <a href="/A018796/b018796.txt">Table of n, a(n) for n = 0..100000</a> (first 10000 terms from Chai Wah Wu)
%e Among the first 100001 terms, the largest is a(99999) = 99999515529 = 316227^2. - _Zak Seidov_, May 22 2016
%p a:= proc(n) local k,d,x;
%p if issqr(n) then return n
%p else for d from 1 do
%p for k from 0 to 10^d-1 do
%p x:= 10^d*n+k;
%p if issqr(x) then return x fi
%p od
%p od
%p fi
%p end proc:
%p seq(a(n),n=1..100); # _Robert Israel_, Jul 31 2014
%t 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 *)
%o (Python)
%o n = 1
%o while n < 100:
%o for k in range(10**3):
%o if str(k**2).startswith(str(n)):
%o print(k**2,end=', ')
%o break
%o n += 1 # _Derek Orr_, Jul 31 2014
%o (Python)
%o from gmpy2 import isqrt
%o def A018796(n):
%o if n == 0:
%o return 0
%o else:
%o d, nd = 1, n
%o while True:
%o x = (isqrt(nd-1)+1)**2
%o if x < nd+d:
%o return int(x)
%o d *= 10
%o nd *= 10 # _Chai Wah Wu_, May 23 2016
%o (PARI) \\Set precision high enough (for the cases where n+1 is a square)!
%o 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
%o } \\ _David A. Corneth_, May 22 2016
%Y Cf. A018851, A077502.
%K nonn,base,easy
%O 0,3
%A _David W. Wilson_
%E a(0)=0 prepended by _Zak Seidov_, May 22 2016