%I #54 Aug 04 2023 23:16:26
%S 1,2,3,1,2,3,4,2,1,2,3,4,2,3,4,1,2,3,4,2,3,4,5,3,1,2,3,4,2,3,4,5,3,2,
%T 3,1,2,3,4,2,3,4,5,3,2,3,4,5,1,2,3,4,2,3,4,5,3,2,3,4,5,3,4,1,2,3,4,2,
%U 3,4,5,3,2,3,4,5,3,4,5,2,1,2,3,4,2,3,4,5,3,2,3,4,5,3,4,5,2,3,4,1,2,3,4
%N Number of positive squares needed to sum to n using the greedy algorithm.
%C Define f(n) = n - x^2 where (x+1)^2 > n >= x^2. a(n) = number of iterations in f(...f(f(n))...) to reach 0.
%C a(n) = 1 iff n is a perfect square.
%C Also sum of digits when writing n in base where place values are squares, cf. A007961. - _Reinhard Zumkeller_, May 08 2011
%C The sequence could have started with a(0)=0. - _Thomas Ordowski_, Jul 12 2014
%C The sequence is not bounded, see A006892. - _Thomas Ordowski_, Jul 13 2014
%H Reinhard Zumkeller, <a href="/A053610/b053610.txt">Table of n, a(n) for n = 1..10000</a>
%F a(n) = A007953(A007961(n)). - _Henry Bottomley_, Jun 01 2000
%F a(n) = a(n - floor(sqrt(n))^2) + 1 = a(A053186(n)) + 1 [with a(0) = 0]. - _Henry Bottomley_, May 16 2000
%F A053610 = A002828 + A062535. - _M. F. Hasler_, Dec 04 2008
%e 7=4+1+1+1, so 7 requires 4 squares using the greedy algorithm, so a(7)=4.
%p A053610 := proc(n)
%p local a,x;
%p a := 0 ;
%p x := n ;
%p while x > 0 do
%p x := x-A048760(x) ;
%p a := a+1 ;
%p end do:
%p a ;
%p end proc: # _R. J. Mathar_, May 13 2016
%t f[n_] := (n - Floor[Sqrt[n]]^2); g[n_] := (m = n; c = 1; While[a = f[m]; a != 0, c++; m = a]; c); Table[ g[n], {n, 1, 105}]
%o (PARI) A053610(n,c=1)=while(n-=sqrtint(n)^2,c++);c \\ _M. F. Hasler_, Dec 04 2008
%o (Haskell)
%o a053610 n = s n $ reverse $ takeWhile (<= n) $ tail a000290_list where
%o s _ [] = 0
%o s m (x:xs) | x > m = s m xs
%o | otherwise = m' + s r xs where (m',r) = divMod m x
%o -- _Reinhard Zumkeller_, May 08 2011
%o (Python)
%o from math import isqrt
%o def A053610(n):
%o c = 0
%o while n:
%o n -= isqrt(n)**2
%o c += 1
%o return c # _Chai Wah Wu_, Aug 01 2023
%Y Cf. A006892 (positions of records), A055401, A007961.
%Y Cf. A000196, A000290, A057945 (summing triangular numbers).
%K nonn
%O 1,2
%A _Jud McCranie_, Mar 19 2000
|