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.

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