cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A018796 Smallest square that begins with n.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

If 4*(n+1) < 10^d then a(n) < (n+1)*10^d. - Robert Israel, Aug 01 2014

Examples

			Among the first 100001 terms, the largest is a(99999) = 99999515529 = 316227^2. - _Zak Seidov_, May 22 2016
		

Crossrefs

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