A018796 Smallest square that begins with n.
0, 1, 25, 36, 4, 529, 64, 729, 81, 9, 100, 1156, 121, 1369, 144, 1521, 16, 1764, 1849, 196, 2025, 2116, 225, 2304, 2401, 25, 2601, 2704, 289, 2916, 3025, 3136, 324, 3364, 3481, 35344, 36, 3721, 3844, 3969, 400, 41209, 4225, 4356, 441, 45369, 4624, 4761, 484, 49
Offset: 0
Examples
Among the first 100001 terms, the largest is a(99999) = 99999515529 = 316227^2. - _Zak Seidov_, May 22 2016
Links
- Zak Seidov, Table of n, a(n) for n = 0..100000 (first 10000 terms from Chai Wah Wu)
Programs
-
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 *)
-
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
-
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
Extensions
a(0)=0 prepended by Zak Seidov, May 22 2016
Comments